声明可浏览类别后Android应用程序不再可用

时间:2017-03-30 09:31:47

标签: android android-manifest deep-linking

在开发一个非常简单的应用程序时,我在向AndroidManifest.xml声明以下行时偶然发现了这种奇怪的行为:

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


            <data android:scheme="com.example.appname"
            android:host="myHost" />

基本上人们可以安装APK,但应用程序会从菜单中消失,无法再启动。通过设置&gt;您可以看到应用程序已安装的应用程序。

所以我创建了一个基本的测试用例,只是一个只有一个加载webview的活动的webview应用程序。将它发布到app商店,正如预期没有问题。推送了具有intent类别的更新,并且同样存在问题。我可以更新到这个较新的版本,但该应用程序已从主页/应用程序屏幕中删除,因此无法启动。

完整的清单文件:

<?xml version="1.0" encoding="utf-8"?>
      <manifest package="com.example.appname"
      xmlns:android="http://schemas.android.com/apk/res/android">

<uses-permission android:name="android.permission.INTERNET"/>

<application
    android:allowBackup="true"
    android:icon="@mipmap/ic_launcher"
    android:label="@string/app_name"
    android:supportsRtl="true"
    android:theme="@style/AppTheme">
    <activity android:name=".MainActivity">
        <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="com.example.appname"
            android:host="myHost" />

        </intent-filter>
    </activity>
</application>

安装在模拟器中或通过设备上的ADB时,应用程序运行正常。可浏览的声明工作正常。

1 个答案:

答案 0 :(得分:3)

您可以为不同的操作声明不同的 intent-filter

<activity
    android:name=".MainActivity"
    android:label="@string/app_name">

    <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" />
        <category android:name="android.intent.category.BROWSABLE" />
        <data android:scheme="http" android:host="www.example.com" android:pathPrefix="/prefix" />
    </intent-filter>

</activity>