如何在 android 中点击 url 启动应用程序

How to launch app on click of url in android

如果设备上安装了应用程序,则单击 url 时启动应用程序。如果应用程序未安装在设备上,请打开 playstore。

<activity android:name=".ui.NewsCardActivity">
    <intent-filter>
        <data android:scheme="app" />
        <action android:name="android.intent.action.VIEW" />
        <category android:name="android.intent.category.DEFAULT" />
        <category android:name="android.intent.category.BROWSABLE" />
    </intent-filter>
</activity>

您必须深入 link 您的应用程序,在要启动的 activity (Manifiest.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:host="screen" android:scheme="appname"/>
</intent-filter>

在浏览器中,只要您单击 appname://screen,您的应用程序 activity 就会启动,

根据您的要求更换应用名称和屏幕

请注意,如果您在浏览器中键入此 url,它将在 google 中搜索,为此您必须在 html 页面中写入 link [=15] =]

<a href="appname://screen">Some text</a>

如果不起作用,请在 activity

中添加 android:exported="true"
<activity
    android:name=".activity.MainActivity"
    android:exported="true">