开发者

Can't launch Android application from within an SMS - Android browser always take the task

开发者 https://www.devze.com 2023-03-01 20:51 出处:网络
I would like my application to launch when the user clicks on a link, for example, http://myapp.comwhich is embedded in an SMS message.

I would like my application to launch when the user clicks on a link, for example, http://myapp.comwhich is embedded in an SMS message.

I have followed this [solution] but it doesn't work for me. The emulator keeps ope开发者_运维技巧ning the browser each time.

Here's the intent filter:

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

I also tried to increase the priority of the intent filter in order to intercept the intent before the browser using the android:priority = 100 tag but it didn't change anything. So either this priority is not high enough or the intent filter didn't match from the beginning.

Here's the intent that the system broadcasts just after clicking on the link. It gave:

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}

My guess is that Android chooses the default browser each time this intent is sent out. I wonder if there is anything to do with the cmp attribute. Can we change it? Otherwise, how can we intercept the intent before the browser?

Any advices would be welcomed. Thank you in advance :)


I updated the emulator tool (actually I removed/re-installed the SDK) and rebuilt the application with exactly the same code. Now it works for all versions above 2.1! When the user clicks on the link in the SMS, a window pops up and proposes Browser and my app.

The broadcast intent is also different this time:

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

The component attribute has changed! So I really think that it's something to do with the emulator's version.


Shouldn't your android:scheme link to your app instead of http?

<data android:scheme="myapp"/> 

Have a look at these Stackoverflow questions for more information (I think you meant to link to one of these in your question where you say "[solution]"):
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

Have you tried calling the setPackage method as described in one of those answers?

Update: I think you may be able to achieve this by using two schemes, perhaps something like this:

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

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号