1

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 opening 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 :)

npittaya
  • 41
  • 3
  • Does your application pick up the link elsewhere? If so, take a peek at the SMS source code and see if they handle links differently http://android.git.kernel.org/?p=platform/packages/apps/Mms.git;a=tree Based on the intent you pasted, it seems like it directly chooses the browser. Maybe try another schema and send a link that way? – Mike dg Apr 28 '11 at 12:59
  • @ Mike dg Thanks for your prompt reply :) No, I crafted the SMS by myself. Now i'm trying to see if I can register a BroadcastReceiver to this intent in order to intercept it. – npittaya Apr 28 '11 at 14:32

2 Answers2

1

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.

npittaya
  • 41
  • 3
0

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/" />
Community
  • 1
  • 1
Dan J
  • 25,433
  • 17
  • 100
  • 173
  • Thanks for your advice and the links. The problem is if I use a custom URI in the SMS, the SMS application cannot recognize it as a clickable link, thus the user can't click it. However, I just found out that on Android 2.3, this schema can work. The system proposes 2 applications that can handle the intent including my app. But on 2.1, the browser always comes up. So maybe it's something to do with how the SMS application is coded in each version... – npittaya Apr 28 '11 at 15:20