Didac Perez Parera
Didac Perez Parera

Reputation: 3824

Launch an app from a link issue in Android

Suppose I have an app with the following intent filter in an activity in the AndroidManifest.xml file:

       <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:host="blabla.com"
                android:pathPrefix="/element/"
                android:scheme="http" />
        </intent-filter>

Of course it will cause my app to be launched from the browser, for example. However, when the user clicks on the link, it is asked to select the application for opening that link. If he/she selects a browser instead of my app and, in addition, he/she checks the "don't ask me again" check box, my app will never be launched!

  1. Is there any way to avoid that?
  2. Is there another kind of URI I can use to uniquely open my app? I have been looking for answers in StackOverflow but I have not found any good example of a non browsable URI for launching my app from a link.

Thank you so much,

Upvotes: 1

Views: 208

Answers (2)

waynetska
waynetska

Reputation: 26

Use an with a element. For example, to handle all links to twitter.com, you'd put this inside your in your AndroidManifest.xml:

<intent-filter>
<data android:scheme="http" android:host="twitter.com"/>
<action android:name="android.intent.action.VIEW" />
</intent-filter>

Then, when the user clicks on a link to twitter in the browser, they will be asked what application to use in order to complete the action: the browser or your application.

Of course, if you want to provide tight integration between your website and your app, you can define your own scheme:

<intent-filter>
<data android:scheme="my.special.scheme" />
<action android:name="android.intent.action.VIEW" />
 </intent-filter>

Then, in your web app you can put links like:

<a href="my.special.scheme://other/parameters/here">
And when the user clicks it, your app will be launched automatically (because it will probably be the only one that can handle my.special.scheme:// type of uris). The only downside to this is that if the user doesn't have the app installed, they'll get a nasty error. And I'm not sure there's any way to check.

Upvotes: 1

petey
petey

Reputation: 17140

  1. Use a custom scheme instead of http. Maybe, x-myapp

        <data
            android:host="blabla.com"
            android:pathPrefix="/element/"
            android:scheme="x-myapp" />
    
  2. Have your blabla.com web server respond to http links (http://blabla.com/element/foo) with a redirect to x-myapp://blabla.com/element/foo for mobile android devices.....or put a link on the page that will have the x-myapp:// link for the user to tap

Now since your app is the only one responding to x-myapp://blabla.com/element/ links, you have avoided step 1.

Upvotes: 0

Related Questions