Android:如何启动我的活动而不是浏览器

时间:2011-11-21 11:09:02

标签: android broadcastreceiver broadcast

我是android的新手,我正在设计一个我想要使用广播接收器的应用程序。通过使用这个我想在有人点击浏览器(默认的android浏览器)时启动我的应用程序。如果有人这样做,请帮助我。

提前致谢。

2 个答案:

答案 0 :(得分:2)

您无法拦截主浏览器的启动,但是,您可以使应用程序处理用于查看URL的意图。为此,请在活动部分的AndroidManifest.xml中添加以下内容:

<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" />
    <data android:scheme="https" />
</intent-filter>

答案 1 :(得分:0)

您可以为某个网址设置intent-filter(使用http方案)。通过这种方式,如果用户浏览已识别的网址,则会启动您的应用而不是网页。

这里有更多细节: http://developer.android.com/guide/topics/intents/intents-filters.html#ifs 和这里: http://developer.android.com/guide/topics/manifest/data-element.html

问候,帕特里克