I am trying to create a link that can be sent via email which when opened on an android device with my app installed will automatically open the correct page in my app.
I have gotten this partially working in a few different ways but have found a few problems that I was wondering if anyone has solutions to.
Attempt 1: Using a custom scheme: myapp://someItem. This works but some email applications do not treat this as a link as it is not http. Is there a way to force applications to treat it as a valid link? gmail for example.
Attempt 2: Using a http link with a host: http://com.myapp/someItem. This works as well but my app ends up registered to handle all http links which is not ideal.
Attempt 3: Using a http link with host and port: http://com.myapp:2345/someItem. This is my current solution with the only drawback being that when the link is opened it still gives the option of opening the link in a browser. Is there a way to stop the browser attempting to open my links?
Does anyone have a way to make links that will be treated as links by all applications and also be ignored by the browser when opening them?
If you can use something server-side, maybe you could have a regular page which jumps to the custom-scheme link from the browser when visited? This has the added advantage of possibly being able to tell if the application is not installed and to prompt installation.
It doesn't fix the problem of links opening in the browser, though. The only true solution I can think of for that is a link-handler that jumps to the appropriate application. Then the issue would be allowing the user to change the preferred browser...
1 - Set Custom URL schemes like http://example.com
For example, the URL http://example.com/?id=95 , will open up the relevant FAQ and the URL http://example.com/?sectionid=8 (where sectionid is the publish id of any Section), will open up relevant section.
2 - Define in your
AndroidManifest.xml
yourDeepLinkActivity
(the one that will receive the URL data:3 - Override the
onResume()
method of yourDeepLinkActivity
class:This technique actually seems to be working on Android from what I can tell:
http://mobile.dzone.com/news/custom-url-schemes-phonegap
I haven't tried it in a real production app yet, so your mileage may vary. What I've done is use that technique of creating a hidden iframe and attempting to set the location to the custom url scheme, and call the function from onload for the document. What I've seen so far (I've only tested it out on 2.2 and 2.3 devices) is that if I have an app installed that handles the custom scheme the app will launch, and if not the page will render.
Relatively clean single URL to cover both cases, and doesn't ruin things like Twitter shares of the URL. A real production version might only do the hidden iframe probe if the request is coming from something that looks like a platform that might support the application to reduce the risk of incompatible desktop behavior.
To answer your questions, below is a sample intent filter in the manifest.
So basically, when some one clicks on any link starting with http://www.example.com/home, he/she will be given the option to open it with your app along with the Browser apps. You have to handle the intent in the activity
Also the scheme could be anything, but http scheme is recommended by google, so that both your app and the browser app can listen to clicks on the deeplinked url.
Note : Don't forget to add android-app://yourpackage name/http/www.example.com/home/... in your web pages, if you want app linking.