是否可以建立这样的链接:
<a href="anton://useful_info_for_anton_app">click me!</a>
让我的安东应用启动吗
我知道这适用于Android Market应用程序的市场协议,但类似的事情是否也适用于其他应用程序?
下面是一个将启动Android Market的链接示例:
<a href="market://search?q=pname:com.nytimes.android">click me!</a>
更新:
我接受eldarerathis提供的答案很好,但我只想提一下,我在<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>
这是我的食谱:
创建一个静态HTML,重定向到你所请求的应用程序URL,把这个页面放在网页上。
这样,你分享的链接就Android而言是“真实的”链接(它们将是“可点击的”)。
你“共享”一个常规的HTTP链接,www.your.server.com/foo/bar.html
这个URL返回一个简单的8行HTML,重定向到应用程序的URI(窗口)。location = "blah://kuku")(注意,'blah'不再是HTTP或HTTPS)。
一旦启动并运行了它,就可以使用上面建议的所有奇特功能来增强HTML。
这适用于内置浏览器Opera和Firefox(还没有测试过任何其他浏览器)。Firefox会提示“这个链接需要用应用程序打开”(好的,取消)。其他浏览器显然不太担心安全性,他们只是打开应用程序,没有任何问题。
试试我的简单技巧:
public boolean shouldOverrideUrlLoading(WebView view, String url) {
if(url.startsWith("classRegister:")) {
Intent MnRegister = new Intent(getApplicationContext(), register.class); startActivity(MnRegister);
}
view.loadUrl(url);
return true;
}
我的HTML链接:
<a href="classRegister:true">Go to register.java</a>
或者你可以为类文件名设置< a href="classRegister:true" > <- "true"值
不过,这个脚本适用于mailto link:)
if (url.startsWith("mailto:")) {
String[] blah_email = url.split(":");
Intent emailIntent = new Intent(android.content.Intent.ACTION_SEND);
emailIntent.setType("text/plain");
emailIntent.putExtra(android.content.Intent.EXTRA_EMAIL, new String[]{blah_email[1]});
emailIntent.putExtra(android.content.Intent.EXTRA_SUBJECT, what_ever_you_want_the_subject_to_be)");
Log.v("NOTICE", "Sending Email to: " + blah_email[1] + " with subject: " + what_ever_you_want_the_subject_to_be);
startActivity(emailIntent);
}