是否可以建立如下链接:
<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) 因此,我想创建一个Android应用程序,以便在Android操作系统中注册(或者只是在系统启动时启动),当手机用户点击网页浏览器内网页上的特殊按钮时:
<a href="myapp://mysettings">Foo</a>
Run Code Online (Sandbox Code Playgroud)
我的应用程序将弹出并使用该URL中发送的参数运行.
那我该怎么做呢?
我需要一个代码教程!
我在特定设备上遇到意图URI问题,所以我尝试了CommonsWare URLHandler示例,如下所示:使用意图URI启动我的应用程序,其示例页面上的意图URI超链接也无法调用应用程序.该示例声明了其intent-filter,如下所示:
<intent-filter>
<action android:name="com.commonsware.android.MY_ACTION" />
<category android:name="android.intent.category.DEFAULT" />
<category android:name="android.intent.category.BROWSABLE" />
</intent-filter>
Run Code Online (Sandbox Code Playgroud)
示例网页中的超链接是:
<a href="intent:#Intent;action=com.commonsware.android.MY_ACTION;end">Link back to URLHandler via intent: URL</a>
Run Code Online (Sandbox Code Playgroud)
这适用于大多数设备,但不适用于运行Android 4.0.3的HTC Amaze 4G.当我触摸链接时,logcat给出:
I/PRIME(9029): <CallBackProxy> Send to WebViewClient.
I/PRIME(9029): <Browser> Send to HtcLinkifyDispatcher
I/ActivityManager(262): START intent from pid 9029
D/MP-Decision(891): Aggress decision engine: Off
D/MP-Decision(891): Switch back to normal parameters:
Nw=2.700000, Tw=180, Ns=2.100000, Ts=270, Decision_ms=100, Poll_ms=10
V/NfcService(600): setForegroundNdefPush msg = null callback = null
D/HtcTelephony(561): requestSetFastDormancy: module=0 mode=0
D/WebViewTimersControl(9029): onBrowserActivityPause
D/WebViewTimersControl(9029): Pausing webview timers,
view=com.android.browser.BrowserWebView@40e562f8 …Run Code Online (Sandbox Code Playgroud)