您的位置:首页 > 移动开发 > Android开发

Android 点击链接打开应用

2013-06-27 16:11 134 查看
昨天遇到这样一个问题,看别人通过短信位置分享,会有一个链接 ,点击链接会提示我们选择用什么打开(浏览器,UC,自己的APP)奇怪的发现为什么还能启动APP抱着好奇的态度我决定一探究竟。

我的第一感觉是在manifest里面加IntentFilter过滤,但是我在data直接加入path的时候不起作用,后来我通过上网上查资料 网上说必须设置schema(http)一切支持链接的头

host(我们链接主体部分)例如www.baidu.com.;

pathPrefix(过滤条件)如果我们要求用htttp://www.baidu.com/s 的地址打开我们自己的应用 我们需要在我们Manifest 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:pathPrefix="/s" android:host="www.baidu.com" android:scheme="http"/>

</intent-filter>

通过这样设置点击网址就可以打开我们自己的应用了

然后我们自己应用中得做处理了

1.如果我们的应用打开了 判断应用活跃的Activity,并直接跳转到当前页面

2.如果没有则直接启动应用

下面分享一些常用的打开浏览器的scheme和mimetype

<intent-filter>

<action android:name="android.intent.action.VIEW" />

<category android:name="android.intent.category.BROWSABLE" />

<category android:name="android.intent.category.DEFAULT" />

<data android:scheme="http" />

<data android:scheme="https" />

<data android:scheme="inline" />

<data android:mimeType="text/html" />

<data android:mimeType="text/plain" />

<data android:mimeType="application/xhtml+xml" />

<data android:mimeType="application/vnd.wap.xhtml+xml" />

</intent-filter>

<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="file" />

</intent-filter>
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: 
相关文章推荐