So I want to create an Android app so it would be registered somewhere in android OS (or just would start on system start) and when phone user clicks on special button on a web page inside a web browser a la:
<a href="myapp://mysettings">Foo</a>
my app would pop up and run using the params sent in that URL.
So how do I do such thing?
I need a tutorial with code!
First, to be able to start your app from link with custom scheme 'myapp' in browser / mail, set intent filter as follows.
<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:scheme="myapp"/> </intent-filter>
and to parse queries in your link myapp://someaction/?var=str&varr=string
(the code is over simplified and has no error checking.)
Intent intent = getIntent(); // check if this intent is started via custom scheme link if (Intent.ACTION_VIEW.equals(intent.getAction())) { Uri uri = intent.getData(); // may be some test here with your custom uri String var = uri.getQueryParameter("var"); // "str" is set String varr = uri.getQueryParameter("varr"); // "string" is set }
[edit] if you use custom scheme to launch your app, one of the problem is that: The WebView in another apps may not understand your custom scheme. This could lead to show 404 page for those browser for the link with custom scheme.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With