Create Custom URL protocol in Android

纵饮孤独 提交于 2021-02-18 18:54:37

问题


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 .


回答1:


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>


来源:https://stackoverflow.com/questions/24031955/create-custom-url-protocol-in-android

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!