Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

how to launch an android app with custom url scheme

I want to launch my app from a custom URL scheme. I checked the deep links section on dev android and here is a snippet of my code. This doesnt seem to fire though with a URL that looks like : myApp://?host=myhost.com

Manifest :

<intent-filter>
    <action android:name="android.intent.action.MAIN" />

    <category android:name="android.intent.category.LAUNCHER" />
    <category android:name="android.intent.category.BROWSABLE" />

    <data android:scheme="myApp" />
</intent-filter>

In the activity which is my main activity, i have :

Intent intent = getIntent();
Uri uri = intent.getData();
if (uri != null) {
    String host = uri.getQueryParameter("host");
}

The app does not launch when i have email that has the url as a hyperlink. Also, what would be a good way to test this ?

like image 952
lokoko Avatar asked Sep 15 '25 01:09

lokoko


1 Answers

Try this, edit your IntentFilter

<intent-filter>
  <action android:name="android.intent.action.VIEW"></action>
  <category android:name="android.intent.category.DEFAULT"></category>
  <category android:name="android.intent.category.BROWSABLE"></category>
  <data android:host="www.youtube.com" android:scheme="http"></data>
</intent-filter>

EDIT

<intent-filter>
    <action android:name="android.intent.action.MAIN" />
    <category android:name="android.intent.category.LAUNCHER" />
</intent-filter>


<intent-filter>
  <action android:name="android.intent.action.VIEW"></action>
  <category android:name="android.intent.category.DEFAULT"></category>
  <category android:name="android.intent.category.BROWSABLE"></category>
  <data android:host="www.youtube.com" android:scheme="http"></data>
</intent-filter>
like image 104
Noman Rafique Avatar answered Sep 16 '25 14:09

Noman Rafique