Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to test custom URL scheme in android

I'm working on app that requires Custom URL Scheme looks like "appname://"

I've searched lot of things and also found many related questions, but I'm still having trouble.

How I can test this URL Scheme from a browser? Currently, whenever I type in a browser's address bar "appname://", it goest directly to a Google search.

I have this in my AndroidManifest.xml:

<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="appname"
             android:host="appnamehost"/>
</intent-filter>
like image 827
DI Developers Avatar asked Aug 07 '15 10:08

DI Developers


People also ask

How can I get Android URI scheme?

To start, you need to pick an Activity within your app that you'd like to open when the URI scheme is triggered and register an intent filter for it. Add the following code within the <activity /> tag within your manifest that corresponds to the Activity you want to open.

How do I find the URL scheme of an app?

Go to the Play store, find the app and view its page. Copy the URL from the browser address bar. Make a note of this as the "Android Fallback URL." You'll see a parameter called "id" followed by an equal sign (=).


1 Answers

That is easy via adb. Check this command:

adb shell am start -a android.intent.action.VIEW -d "appname://appnamehost" your.package.name 

However you should use your package name as schema. So you can be absolutely sure that there is no conflict (or in detail a intent chooser).

If you have multiple devices you need to execute adb devices. This will result a output like this:

List of devices attached 1645e1d0b86b    device S9WM00904386    device 

Then you can use that id from above to address a concrete device with the -s parameter. This will result a command line like this:

adb -s S9WM00904386 shell [...] 

In case of a browser link this is also easy. You just need to add this line of html:

<a href="appname://appnamehost">Click me</a> 

If you want a fallback in your url you could try the intent url:

<a href="intent://apphostname#Intent;scheme=appname;package=your.package.name;S.browser_fallback_url=http%3A%2F%2Fwww.example.com;end">with alternative</a> 

This will open your app even if you schema is not unique, and if you app is not installed it will open example.com.

like image 199
rekire Avatar answered Sep 19 '22 17:09

rekire