Android应用程序Intent过滤器有时无法正常工作。

6

在一个项目中,我遇到了一个非常奇怪的问题:

深度链接在过去一年里一直表现得非常好,但最近(自2019年1月初以来),我们收到了用户反馈,称深度链接已经停止工作(有人说10次中有9次失败)。

我们没有更改任何代码,并且很难复制这个问题。

更奇怪的是,在我们自己遇到这个问题的稀少时刻,Android操作系统甚至不会通过“打开方式”对话框显示我们的应用程序选项。这使我们认为,该操作系统有时会忘记应用程序在其清单中注册的意图过滤器。

重新启动应用程序似乎可以解决这个问题,并且深层链接再次开始工作。 当我们从Android Studio进行新的构建时,应用程序也似乎每次都正常工作,这使问题很难复制。

我们的清单有一个专门处理深度链接的活动:

<activity
    android:name="com.company.DeepLinkActivity"
    android:noHistory="true"
    android:launchMode="singleTask">
    <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="ideal-payment"
            android:scheme="com.company.ideal" />
        <data
            android:host="ideal-payment"
            android:scheme="com-company-ideal" />

    </intent-filter>

    <intent-filter android:autoVerify="true">
        <action   android:name="android.intent.action.VIEW" />
        <category android:name="android.intent.category.DEFAULT" />
        <category android:name="android.intent.category.BROWSABLE" />

        <data
            android:host="${appLinkIdealHost}"
            android:pathPrefix="/ideal-betaling/landingpage"
            android:scheme="https" />
    </intent-filter>

    <intent-filter android:autoVerify="true">
        ...
    </intent-filter>

    <intent-filter android:autoVerify="true">
        ...
    </intent-filter>
</activity>

我们认为这可能与autoVerify无法访问有关,但当问题出现时,操作系统应该显示'打开方式'对话框,但实际上并没有。

是否有人遇到过类似的问题?非常感谢任何帮助或建议。


你能指定那个操作系统版本无法使用意图过滤器吗? - Saeed Entezari
还有,制造商/设备。可能是设备特定的。 - Shark
它是在手动强制停止后发生的吗?还是当应用程序被排名为“罕见”的应用待机桶时发生的? - Simon Marquis
我们看到这种情况发生在设备被置于后台一段时间后。当应用再次启动时,问题似乎会消失。 我们遇到此问题的设备和操作系统版本范围相当广泛,例如:华为 P10(8.0),Galaxy A5(8.0),OnePlus 6(9.0),Mate 10 Pro(9.0),Mate 8(7.0),P9 Lite(6.0.1),荣耀9(8.0),P20 Lite(8.0),OnePlus 2(6.0),Vivo1723(8.1)。 - Spoetnic
4个回答

1
当应用程序停止运行时,例如由于异常或用户从设置中强制停止它,或者在某些设备上,当用户将应用程序从历史记录(或任务)中删除时,应用程序将自动强制停止(这不是制造商的好选择)。当应用程序处于停止状态时,其清单中的intentFilter将不会被使用(当应用程序第一次安装并且从未打开时也处于此阶段)。 在停止状态下,应用程序不会以任何原因运行,除非手动启动活动或明确针对活动、服务或广播的意图。

https://riptutorial.com/android/example/30592/android-stopped-state


你提到的大多数Android版本都是8或更高版本,因此下面的引用也可能对服务和广播接收器有用。

每当一个应用在后台运行时,它会消耗一些设备的有限资源,比如RAM。这可能会导致用户体验受损,特别是如果用户使用资源密集型的应用程序,例如玩游戏或观看视频。 为了改善用户体验,Android 8.0(API级别26)对应用程序在后台运行时的功能进行了限制。

https://developer.android.com/about/versions/oreo/background


0

你能指定 Android 操作系统的版本吗?因为 android:autoVerify="true" 只在 Android 6.0 及更高版本上工作,以使系统尝试验证与应用程序意图过滤器中 URL 相关联的所有主机。


我们发现这种情况通常发生在设备被置于后台一段时间后。当应用程序再次启动时,问题似乎会消失。我们遇到此类问题的设备和操作系统版本范围非常广泛,例如:华为P10(8.0),Galaxy A5(8.0),Oneplus 6(9.0),Mate 10Pro(9.0),Mate 8(7.0),P9 lite(6.0.1),Honor 9(8.0),P20 Lite(8.0),OnePlus 2(6.0),Vivo1723(8.1)。 - Spoetnic

0

0

这两个条目对我来说也看起来很奇怪,不确定你想要实现什么:

<data android:host="ideal-payment" android:scheme="com.company.ideal" />
<data android:host="ideal-payment" android:scheme="com-company-ideal" />

这远远不是理想的情况,因为这些主机和方案都是无效的,请参见 data-element

根据所有显然被保留的代码,我会假设其他 intent-filter 也可能具有重复的 data 元素,需要移动到单独的 intent-filter 中,其中一个 activity 元素允许多个。在所有这些 intent-filter 上设置 android:autoVerify="true",然后在软件包安装后仔细查看 logcat。


网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接