无法从SMS内启动Android应用程序 - Android浏览器始终承担任务

时间:2011-04-28 12:52:26

标签: android android-manifest launching-application

我希望我的应用程序在用户点击链接时启动,例如,http://myapp.com嵌入在短信中。

我已按照此[解决方案]但它对我不起作用。模拟器每次都会打开浏览器。

这是意图过滤器:

<intent-filter>    
    <action android:name="android.intent.action.VIEW" />    
    <category android:name="android.intent.catagory.DEFAULT"/> 
    <category android:name="android.intent.catagory.BROWSABLE"/>    
    <data android:host="myapp.com" android:scheme="http" />
</intent-filter>

我还尝试提高intent过滤器的优先级,以便在浏览器使用android:priority = 100标记之前截取意图,但它没有改变任何内容。所以要么这个优先级不够高,要么意图过滤器从一开始就不匹配。

这是系统在点击链接后广播的意图。它给了:

04-27 13:03:22.905: INFO/ActivityManager(59): Starting activity: Intent { act=android.intent.action.VIEW dat=http://myapp.com cmp=com.android.browser/.BrowserActivity}

我的猜测是Android每次发出此意图时都会选择默认浏览器。我想知道是否与cmp属性有关。我们可以改变它吗?否则,我们如何在浏览器之前截取意图?

任何建议都会受到欢迎。提前谢谢你:)

2 个答案:

答案 0 :(得分:1)

我更新了模拟器工具(实际上我删除/重新安装了SDK)并使用完全相同的代码重建了应用程序。现在它适用于2.1以上的所有版本!当用户点击SMS中的链接时,会弹出一个窗口并建议浏览器和我的应用程序。

这次广播意图也不同了:

04-29 12:42:22.906: INFO/ActivityManager(63): Starting activity: Intent { act=android.intent.action.VIEW dat=http://www.my.com flg=0x80000 cmp = android / com.android.internal.app.ResolverActivity (has extras) }

组件属性已更改!所以我真的认为这与模拟器的版本有关。

答案 1 :(得分:0)

你的android:scheme不应该链接到你的应用而不是http吗?

<data android:scheme="myapp"/> 

请查看这些Stackoverflow问题以获取更多信息(我认为您的意思是在您的问题中链接到其中一个,您说“[解决方案]”):
How to register some URL namespace (myapp://app.start/) for accessing your program by calling a URL in browser in Android OS?
How to implement my very own URI scheme on Android

您是否尝试按其中一个答案中的说明调用setPackage method

更新:我认为您可以通过使用两种方案来实现这一目标,可能是这样的:

<data android:scheme="myapp" android:host="launch" android:pathPrefix="/" />
<data android:scheme="http" android:host="myapp" android:pathPrefix="/launch/" />