Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/220.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java NFC-OnNewIntent()有时无法在android设备上工作_Java_Android_Nfc - Fatal编程技术网

Java NFC-OnNewIntent()有时无法在android设备上工作

Java NFC-OnNewIntent()有时无法在android设备上工作,java,android,nfc,Java,Android,Nfc,我一直在我的应用程序中检测到NFC功能卡,以读取标签值。下面是我的代码 OnCreate() 重新开始 nfcAdapter = NfcAdapter.getDefaultAdapter(AuthDriverCard.this); piTap = PendingIntent.getActivity( this, TAP_REQUEST_CODE, new Intent(this, getClass()).addFlags(Intent.FLAG_ACTIVITY

我一直在我的应用程序中检测到NFC功能卡,以读取标签值。下面是我的代码

OnCreate()

重新开始

 nfcAdapter = NfcAdapter.getDefaultAdapter(AuthDriverCard.this);
    piTap = PendingIntent.getActivity(
            this, TAP_REQUEST_CODE, new Intent(this, getClass()).addFlags(Intent.FLAG_ACTIVITY_SINGLE_TOP), PendingIntent.FLAG_UPDATE_CURRENT);
    IntentFilter tagDetected = new IntentFilter(NfcAdapter.ACTION_TAG_DISCOVERED);
    IntentFilter ndefDetected = new IntentFilter(NfcAdapter.ACTION_NDEF_DISCOVERED);
    IntentFilter techDetected = new IntentFilter(NfcAdapter.ACTION_TECH_DISCOVERED);
    nfcIntentFilter = new IntentFilter[]{techDetected, tagDetected, ndefDetected};
 if (nfcAdapter != null) {
        nfcAdapter.enableForegroundDispatch(AuthDriverCard.this, piTap, nfcIntentFilter, null);
    }
 if (nfcAdapter != null) {
        nfcAdapter.enableForegroundDispatch(AuthDriverCard.this, piTap, nfcIntentFilter, null);
    }
暂停

 nfcAdapter = NfcAdapter.getDefaultAdapter(AuthDriverCard.this);
    piTap = PendingIntent.getActivity(
            this, TAP_REQUEST_CODE, new Intent(this, getClass()).addFlags(Intent.FLAG_ACTIVITY_SINGLE_TOP), PendingIntent.FLAG_UPDATE_CURRENT);
    IntentFilter tagDetected = new IntentFilter(NfcAdapter.ACTION_TAG_DISCOVERED);
    IntentFilter ndefDetected = new IntentFilter(NfcAdapter.ACTION_NDEF_DISCOVERED);
    IntentFilter techDetected = new IntentFilter(NfcAdapter.ACTION_TECH_DISCOVERED);
    nfcIntentFilter = new IntentFilter[]{techDetected, tagDetected, ndefDetected};
 if (nfcAdapter != null) {
        nfcAdapter.enableForegroundDispatch(AuthDriverCard.this, piTap, nfcIntentFilter, null);
    }
 if (nfcAdapter != null) {
        nfcAdapter.enableForegroundDispatch(AuthDriverCard.this, piTap, nfcIntentFilter, null);
    }
OnNewIntent()

这段代码几乎每次都能正常工作。但有一段时间,
卡没有检测到
,我发现
OnNewIntent()没有启动

有什么问题吗。我是否也需要在清单中设置意图过滤器?到目前为止,我还没有在清单中设置它,但它对我来说没有任何问题。我的java代码中有问题吗

请建议


注意-重启(关闭应用程序后)应用程序解决问题。卡检测在此之后工作。

如果尚未添加,则需要在清单文件的意向过滤器部分添加以下内容:

<action android:name="android.nfc.action.NDEF_DISCOVERED"/>
<action android:name="android.nfc.action.TAG_DISCOVERED"/>
<action android:name="android.nfc.action.TECH_DISCOVERED"/>

例如:


如果尚未添加,则需要在清单文件的意向过滤器部分添加以下内容:

<action android:name="android.nfc.action.NDEF_DISCOVERED"/>
<action android:name="android.nfc.action.TAG_DISCOVERED"/>
<action android:name="android.nfc.action.TECH_DISCOVERED"/>

例如:



在何处添加此项。我已经在
nfcAdapter.enableForegroundDispatch()函数中添加了此过滤器call@RajeevKumar我已经用更多的细节更新了答案。但是我使用前台调度方法。我不会开启任何预先想要的标签检测活动。我在前台已经有一个活动,如果卡通过前台调度通道检测到,我需要显示该活动的数据。请把我的问题和内容通读一遍。我在前台调度中的问题
有时不工作。我需要重新启动应用程序使其再次工作。为什么?在哪里添加这个。我已经在
nfcAdapter.enableForegroundDispatch()函数中添加了此过滤器call@RajeevKumar我已经用更多的细节更新了答案。但是我使用前台调度方法。我不会开启任何预先想要的标签检测活动。我在前台已经有一个活动,如果卡通过前台调度通道检测到,我需要显示该活动的数据。请把我的问题和内容通读一遍。我在前台调度中的问题
有时不工作。我需要重新启动应用程序使其再次工作。为什么?