是否可以建立如下链接:
<a href="anton://useful_info_for_anton_app">click me!</a>
Run Code Online (Sandbox Code Playgroud)
导致我的Anton应用程序启动?
我知道这适用于具有市场协议的Android Market应用程序,但是可以与其他应用程序类似吗?
以下是启动Android电子市场的链接示例:
<a href="market://search?q=pname:com.nytimes.android">click me!</a>
Run Code Online (Sandbox Code Playgroud)
更新:
我接受eldarerat提供的答案很有用,但我只想提一下,我对<intent-filter>标签的子元素的顺序有些麻烦.我建议您只<intent-filter>使用该标签中的新子元素制作另一个,以避免我遇到的问题.例如我AndroidManifest.xml看起来像这样:
<activity android:name=".AntonWorld"
android:label="@string/app_name">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
<intent-filter>
<data android:scheme="anton" />
<action android:name="android.intent.action.VIEW" />
<category android:name="android.intent.category.BROWSABLE" />
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
</activity>
Run Code Online (Sandbox Code Playgroud)
hac*_*bod 274
请不要使用你自己的定制方案!URI方案是网络全局命名空间.你在世界范围内拥有"anton:"计划吗?没有?然后不要使用它.
一种选择是拥有一个网站,并为该网站上的特定URI设置一个intent-filter.例如,这就是Market在其网站上拦截URI所做的事情:
<intent-filter>
<action android:name="android.intent.action.VIEW" />
<category android:name="android.intent.category.DEFAULT" />
<category android:name="android.intent.category.BROWSABLE" />
<data android:scheme="http" android:host="market.android.com"
android:path="/search" />
</intent-filter>
Run Code Online (Sandbox Code Playgroud)
或者,有"意图:"方案.这允许您将几乎任何Intent描述为URI,浏览器在单击时将尝试启动它.要构建这样的方案,最好的方法是只编写代码来构造要启动的Intent,然后打印intent.toUri(Intent.URI_INTENT_SCHEME)的结果.
您可以使用具有此意图的操作来查找支持该操作的任何活动.出于安全原因,浏览器会在启动之前自动将BROWSABLE类别添加到intent中; 它也会因同样的原因剥离你提供的任何显式组件.
使用它的最佳方法是,如果你想确保它只启动你的应用程序,则使用你自己的作用域操作并使用Intent.setPackage()来表示Intent只匹配你的应用程序包.
两者之间的权衡:
http URI要求您拥有自己的域.用户将始终获得在浏览器中显示URI的选项.它具有非常好的后备属性,如果您的应用程序未安装,它们将简单地登陆您的网站.
意图URI要求您的应用程序已安装且仅在Android手机上安装.允许几乎任何意图(但始终包含BROWSABLE类别,不支持显式组件).它们允许您将启动定向到您的应用程序,而无需用户选择转到浏览器或任何其他应用程序.
eld*_*his 94
我想你会想看看<intent-filter>你的Mainfest文件的元素.具体来说,请查看<data>子元素的文档.
基本上,您需要做的是定义自己的方案.有点像:
<intent-filter>
<data android:scheme="anton" />
<action android:name="android.intent.action.VIEW" />
<category android:name="android.intent.category.DEFAULT" />
<category android:name="android.intent.category.BROWSABLE" /> <--Not positive if this one is needed
...
</intent-filter>
Run Code Online (Sandbox Code Playgroud)
然后,您应该能够使用以anton:URI方案开头的链接启动您的应用程序.
Lit*_*ito 13
我为推销自己道歉,但我有一个jQuery插件,可以通过网络链接启动原生应用程序https://github.com/eusonlito/jquery.applink
你可以轻松使用它:
<script>
$('a[data-applink]').applink();
</script>
<a href="https://facebook.com/me" data-applink="fb://profile">My Facebook Profile</a>
Run Code Online (Sandbox Code Playgroud)
小智 12
我也遇到过这个问题,看到很多荒谬的页面.我已经了解到要使您的应用程序可浏览,请更改XML元素的顺序,这个:
<activity
android:name="com.example.MianActivityName"
android:label="@string/title_activity_launcher">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
<intent-filter>
<data android:scheme="http" />
<!-- or you can use deep linking like -->
<data android:scheme="http" android:host="xyz.abc.com"/>
<action android:name="android.intent.action.VIEW"/>
<category android:name="android.intent.category.BROWSABLE"/>
<category android:name="android.intent.category.DEFAULT"/>
</intent-filter>
</activity>
Run Code Online (Sandbox Code Playgroud)
这对我有用,可能会对你有所帮助.
这是我的食谱:
创建一个静态HTML,重定向到您请求的应用程序URL,将该页面放在Web上.
这样,就Android而言,您分享的链接是"真正的"链接(它们将是"可点击的").
您共享'常规HTTP链接,www.your.server.com/foo/bar.html此URL返回一个简单的8行HTML,重定向到您应用的URI(window.location ="blah:// kuku")(请注意''blah'不必再是HTTP或HTTPS了).
一旦启动并运行,您可以使用上面建议的所有花哨功能来扩充HTML.
这适用于内置浏览器,Opera和Firefox(尚未测试任何其他浏览器).Firefox询问'此链接需要使用应用程序打开'(确定,取消).其他浏览器显然不担心安全性,他们只是打开应用程序,没有问题.
此方法不会调用消歧对话框,要求您打开应用程序或浏览器。
如果您在清单中注册以下内容
<manifest package="com.myApp" .. >
<application ...>
<activity ...>
<intent-filter>
<action android:name="android.intent.action.VIEW" />
<category android:name="android.intent.category.DEFAULT" />
<category android:name="android.intent.category.BROWSABLE" />
<data
android:host="gallery"
android:scheme="myApp" />
</intent-filter>
</activity>
..
Run Code Online (Sandbox Code Playgroud)
例如,点击手机上电子邮件中的此网址
<a href="intent://gallery?directLink=true#Intent;scheme=myApp;package=com.myApp;end">
Click me
</a>
Run Code Online (Sandbox Code Playgroud)
然后 android 会尝试找到一个带有com.myApp包的应用程序,该应用程序响应您的图库意图并具有myApp方案。如果它不能,它会带你到商店,寻找com.myApp,这应该是你的应用程序。
| 归档时间: |
|
| 查看次数: |
238944 次 |
| 最近记录: |