1

How can I create a custom protocol in Android?

I have tried this code:

<activity android:name=".MyActivity" android:label="@string/app_name">
<!-- open the app when a foo://www.example.com link is clicked -->
<intent-filter>
    <action android:name="android.intent.action.VIEW" />
    <category android:name="android.intent.category.BROWSABLE" />
    <category android:name="android.intent.category.DEFAULT" />
    <data android:scheme="foo" />
</intent-filter>

Register this in Manifest file and call in browser like this foo://hello but it not open my app .

Shmwel
  • 1,697
  • 5
  • 26
  • 43

1 Answers1

3

I remember having similar problem a while back. Hope my solution will help you solve yours. Add android:exported="true" and move <data android:scheme="foo" /> on top.

<activity android:name=".MyActivity" android:label="@string/app_name"
android:exported="true">
<!-- open the app when a foo://www.example.com link is clicked -->
<intent-filter>
    <data android:scheme="foo" />

    <action android:name="android.intent.action.VIEW" />
    <category android:name="android.intent.category.BROWSABLE" />
    <category android:name="android.intent.category.DEFAULT" />
</intent-filter>
Community
  • 1
  • 1
Lazy Ninja
  • 22,342
  • 9
  • 83
  • 103