【发布时间】:2020-06-18 23:17:39
【问题描述】:
我实现了一个读取 QR 码并以模式显示结果的应用程序(然后,如果结果是 URL,则在 WebView 上重定向)。它运作良好。 但现在我想做的是:当使用我设备的相机(不是我的应用程序)扫描二维码时,它会启动我的应用程序并在我的模式中显示结果。
我使用了意图过滤器来做到这一点......而且效果也很好!但问题是它不仅会在扫描二维码的情况下启动我的应用程序。例如,当我单击手机上的 URL 时,它会启动我的应用程序。这不是我想要的行为。我希望它仅在从 QR 码中检测到 URL 时启动我的应用程序。有可能吗?
这是我的清单
<activity
android:launchMode="singleTask"
android:name=".MainActivity"
android:screenOrientation="portrait">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
<intent-filter>
<action android:name="android.nfc.action.NDEF_DISCOVERED" />
<category android:name="android.intent.category.DEFAULT" />
<data android:scheme="http" />
<data android:scheme="https" />
</intent-filter>
<intent-filter>
<action android:name="android.nfc.action.TECH_DISCOVERED" />
</intent-filter>
<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="http" android:host="*"/>
<data android:scheme="https" android:host="*"/>
</intent-filter>
<meta-data
android:name="android.nfc.action.TECH_DISCOVERED"
android:resource="@xml/nfc_tech_filter" />
</activity>
【问题讨论】:
标签: android android-intent android-manifest