当应用程序处于前台时阻止活动选择器对话框

问题描述 投票:0回答:1

我的应用程序应该检测到NFC card。检测到卡后,将显示“活动选择器”对话框,然后在从对话框中点击应用程序时,将打开相应的应用程序。但是我需要阻止活动选择器对话框在app is in foreground时显示,所以我正在使用此:

pendingIntent = PendingIntent.getActivity(this, 0, new Intent(this, getClass()).addFlags(Intent.FLAG_ACTIVITY_SINGLE_TOP), 0);

这是来自AndroidManifest.xml的代码:

<activity
        android:name=".ui.base.DeepLinkActivity"
        android:theme="@style/Theme.Transparent">
        <intent-filter>
            <action android:name="android.nfc.action.NDEF_DISCOVERED" />
            <category android:name="android.intent.category.DEFAULT" />
            <data android:mimeType="text/plain" />
        </intent-filter>

        <intent-filter>
            <action android:name="android.nfc.action.TAG_DISCOVERED" />
        </intent-filter>

        <intent-filter>
            <action android:name="android.nfc.action.TECH_DISCOVERED" />
        </intent-filter>

        <meta-data
            android:name="android.nfc.action.TECH_DISCOVERED"
            android:resource="@xml/nfc_tech_filter" />
    </activity>

如果只有一项活动,则可以使用ForegroundDispatch阻止活动选择器对话框。但是现在的问题是我的应用程序有多个活动,并且无论应用程序在屏幕上显示什么,只要应用程序处于前台,我都需要阻止活动选择器对话框。

android android-activity nfc
1个回答
0
投票

您需要在您应用程序的所有活动中实施前台分派,如果您只想阻止卡,则onNewIntent应该是空卡,则不执行任何操作

© www.soinside.com 2019 - 2024. All rights reserved.