防止多个意图过滤器匹配 oauth 重定向

问题描述

在我的应用程序中收到 OAuth 重定向时,Android“打开方式”菜单显示有 2 个选项,这两个选项都是我的应用程序。所需的行为是直接进入应用而不显示“打开方式”菜单

在我添加一个新的意图过滤器来捕获来自其他应用程序的“文本/纯文本”共享后,这个问题开始发生。

这是我的意图过滤器,它们是同一活动的一部分:

<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:scheme="com.app" android:host="app" android:pathPrefix="" />
   <data android:scheme="com.app" android:host="oauth" android:pathPrefix="" />
</intent-filter>
<intent-filter>
    <action android:name="android.intent.action.SEND" />
    <category android:name="android.intent.category.DEFAULT" />
    <data android:mimeType="text/plain" />
</intent-filter>

使用 adb logcat 捕获的意图:

{act=android.intent.action.VIEW cat=[android.intent.category.broWSABLE] dat=com.app://oauth?code=4pZliH2NrWWoypXnsBqEOjbMramW70&state=6aimyjKHt7ZhYPuk_pJjRQ flg=0x14000000 pkg=com.app cmp=android/com.android.internal.app.ResolverActivity (has extras)}

因为它们是同一个活动的一部分,所以我认为它不会提示用户选择一个选项。我还假设 action.VIEW 也只会匹配第一个意图。

尝试组合意图时,重定向完全失败。从研究来看,似乎没有办法对意图进行优先排序。

任何建议将不胜感激。谢谢!

解决方法

Check here

您正在同一个意图过滤器中创建两个同名的方案。

,

我发现了这个问题。我正在使用一个库(AppAuth-Android),它正在注入自己的......

删除库后,问题得到解决。谢谢建议!