Is it possible to make a link such as:
<a href="anton://useful_info_for_anton_app">click me!</a>
cause my Anton app to start up?
I know that this works for the Android Market app with the market protocol, but can something similar be done with other apps?
Here is an example of a link that will start up the Android Market:
<a href="market://search?q=pname:com.nytimes.android">click me!</a>
Update:
The answer I accepted provided by eldarerathis works great, but I just want to mention that I had some trouble with the order of the subelements of the <intent-filter>
tag. I suggest you simply make another <intent-filter>
with the new subelements in that tag to avoid the problems I had. For instance my AndroidManifest.xml
looks like this:
<activity android:name=".AntonWorld"
android:label="@string/app_name">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
<intent-filter>
<data android:scheme="anton" />
<action android:name="android.intent.action.VIEW" />
<category android:name="android.intent.category.BROWSABLE" />
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
</activity>
I think you'll want to look at the
<intent-filter>
element of your Mainfest file. Specifically, take a look at the documentation for the<data>
sub-element.Basically, what you'll need to do is define your own scheme. Something along the lines of:
Then you should be able to launch your app with links that begin with the
anton:
URI scheme.I apologize for promoting myself, but I have a jQuery plugin to launch native apps from web links https://github.com/eusonlito/jquery.applink
You can use it easy:
I also faced this issue and see many absurd pages. I've learned that to make your app browsable, change the order of the XML elements, this this:
This worked for me and might help you.
Here's my recipe:
Create a static HTML that redirects to your requested app URL, put that page on the web.
That way, the links you share are 'real' links as far as Android is concerned ( they will be 'clickable').
You 'share' a regular HTTP link, www.your.server.com/foo/bar.html This URL returns a simple 8 line HTML that redirects to your app's URI (window.location = "blah://kuku") (note that 'blah' doesn't have to be HTTP or HTTPS any more).
Once you get this up and running, you can augment the HTML with all the fancy capabilities as suggested above.
This works with the built-in browser, Opera, and Firefox (haven't tested any other browser). Firefox asks 'This link needs to be opened with an application' (ok, cancel). Other browsers apparently don't worry about security that much, they just open the app, no questions asked.
You may want to consider a library to handle the deep link to your app:
https://github.com/airbnb/DeepLinkDispatch
You can add the intent filter on an annotated Activity like people suggested above. It will handle the routing and parsing of parameters for all of your deep links. For example, your MainActivity might have something like this:
It can also handle query parameters as well.
Please DO NOT use your own custom scheme like that!!! URI schemes are a network global namespace. Do you own the "anton:" scheme world-wide? No? Then DON'T use it.
One option is to have a web site, and have an intent-filter for a particular URI on that web site. For example, this is what Market does to intercept URIs on its web site:
Alternatively, there is the "intent:" scheme. This allows you to describe nearly any Intent as a URI, which the browser will try to launch when clicked. To build such a scheme, the best way is to just write the code to construct the Intent you want launched, and then print the result of intent.toUri(Intent.URI_INTENT_SCHEME).
You can use an action with this intent for to find any activity supporting that action. The browser will automatically add the BROWSABLE category to the intent before launching it, for security reasons; it also will strip any explicit component you have supplied for the same reason.
The best way to use this, if you want to ensure it launches only your app, is with your own scoped action and using Intent.setPackage() to say the Intent will only match your app package.
Trade-offs between the two:
http URIs require you have a domain you own. The user will always get the option to show the URI in the browser. It has very nice fall-back properties where if your app is not installed, they will simply land on your web site.
intent URIs require that your app already be installed and only on Android phones. The allow nearly any intent (but always have the BROWSABLE category included and not supporting explicit components). They allow you to direct the launch to only your app without the user having the option of instead going to the browser or any other app.