在 Android 浏览器中创建一个链接来启动我的应用程序? [英] Make a link in the Android browser start up my app?

查看:24
本文介绍了在 Android 浏览器中创建一个链接来启动我的应用程序?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

是否可以做如下链接:

<a href="anton://useful_info_for_anton_app">click me!</a>

导致我的 Anton 应用启动?

cause my Anton app to start up?

我知道这适用于具有市场协议的 Android Market 应用程序,但其他应用程序可以做类似的事情吗?

I know that this works for the Android Market app with the market protocol, but can something similar be done with other apps?

以下是启动 Android Market 的链接示例:

Here is an example of a link that will start up the Android Market:

<a href="market://search?q=pname:com.nytimes.android">click me!</a>

更新:eldarerathis 提供的我接受的答案效果很好,但我只想提一下,我在 <intent-filter> 标记的子元素的顺序上遇到了一些问题.我建议您只需使用该标记中的新子元素制作另一个 <intent-filter> 以避免我遇到的问题.例如我的 AndroidManifest.xml 看起来像这样:

Update: The answer I accepted provided by eldarerathis works great, but I just want to mention that I had some trouble with the order of the subelements of the <intent-filter> tag. I suggest you simply make another <intent-filter> with the new subelements in that tag to avoid the problems I had. For instance my AndroidManifest.xml looks like this:

<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>

推荐答案

我想你会想看看 <intent-filter> 清单文件的元素.具体来说,请查看 <data> 的文档; 子元素.

I think you'll want to look at the <intent-filter> element of your Manifest file. Specifically, take a look at the documentation for the <data> sub-element.

基本上,您需要做的是定义自己的方案.大致如下:

Basically, what you'll need to do is define your own scheme. Something along the lines of:

<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>

然后您应该能够使用以 anton: URI 方案开头的链接启动您的应用程序.

Then you should be able to launch your app with links that begin with the anton: URI scheme.

这篇关于在 Android 浏览器中创建一个链接来启动我的应用程序?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆