Im trying to create my own url scheme so my android app can get called via an URL but for now I dont have a success.
Im trying to have this url to work : cedemo://com.cedemo.scan?X=toto
Here is part of my manifest file :
<activity android:name=".Gallery1" android:label="@string/app_name" android:launchMode="singleTask" android:screenOrientation="portrait"> <intent-filter> <action android:name="android.intent.action.GALLERY" /> <category android:name="android.intent.category.DEFAULT" /> <category android:name="android.intent.category.BROWSABLE" /> <data android:scheme="cedemo" android:host="com.cedemo.scan" /> </intent-filter> </activity>
Does anyone can help telling me what is wrong ? Also, if someone find what is wrong, can someone tell me how I read the "X" variable from inside the android code from my app ?
Update:
Update: I did the modification of the action (as advised in one of the answers) and it's worked fine. The thing is that I still cannot get the url variable value. Here is the code I tried.
final Intent intent = getIntent(); final String myScheme=intent.getScheme(); final Bundle myBundle=intent.getExtras(); final boolean inContestKey; if (myBundle != null) { inContestKey=myBundle.containsKey("inContest"); } final Uri myURI=intent.getData(); final String value; if (myURI != null) { value = myURI.getQueryParameter("inContest"); }
But I receiving null
from all the functions… what else can i do?
May be I should explain better the context of my software:
But in my case : myScheme
, myBundle
, myURI
are set to null
.
Any ideas ?
Update:
I found the answer is that you have to be in the main activity to do that.
In Android 1.0, the Android URI scheme deep linking mechanism was created. It allows the developer to register their app for a URI (uniform resource identifier) in the operating system for a specific device once the app is installed.
Custom URL schemes provide a way to reference resources inside your app. Users tapping a custom URL in an email, for example, launch your app in a specified context. Other apps can also trigger your app to launch with specific context data; for example, a photo library app might display a specified image.
In Android, a deep link is a link that takes you directly to a specific destination within an app. The Navigation component lets you create two different types of deep links: explicit and implicit.
I think the problem is with the Action you defined. There is a "android.intent.action.VIEW" which is what I think you want.
<activity android:name=".Gallery1" android:label="@string/app_name" android:launchMode="singleTask" android:screenOrientation="portrait"> <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="cedemo" android:host="com.cedemo.scan" /> </intent-filter> </activity>
Try that and I bet will resolve correctly. I only made this assumption because you included the browsable category which is usually used by the Browser, which does not know of any of your custom actions. If you do want the GALLERY action as you have implied then just create 2 filters
<activity android:name=".Gallery1" android:label="@string/app_name" android:launchMode="singleTask" android:screenOrientation="portrait"> <intent-filter> <action android:name="android.intent.action.GALLERY" /> <category android:name="android.intent.category.DEFAULT" /> <category android:name="android.intent.category.BROWSABLE" /> <data android:scheme="cedemo" android:host="com.cedemo.scan" /> </intent-filter> <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="cedemo" android:host="com.cedemo.scan" /> </intent-filter> </activity>
So within the contents of your activity you can do something like:
// Value should be "toto" as in your example String value = getData().getQueryParameter("X");
What finally fixed things for me was changing the order of the XML elements. Specifically, swapping the data and action rows so data is before action made it start working.
<intent-filter> <data android:scheme="myappname" /> <action android:name="android.intent.action.VIEW" /> <category android:name="android.intent.category.BROWSABLE" /> <category android:name="android.intent.category.DEFAULT" /> </intent-filter>
And for completeness, my link in the html is "myappname://noop".
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