Пытаюсь определить наличие NFC, но onNewIntent не вызывается

#android #android-studio #nfc #texas-instruments

Вопрос:

Я пытаюсь обнаружить свой NFC в моем RF430FRL152H в Android studio. Моя цель состоит в том, чтобы, если NFC обнаружен, открыть новое действие из main. Это мое главное на данный момент:

 public class MainActivity extends AppCompatActivity {
    //Initialize the attributes
    NfcAdapter nfcAdapter;
    PendingIntent pendingIntent;
    final static String TAG = "nfc_test";
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        //Initialise NfcAdapter
        nfcAdapter = NfcAdapter.getDefaultAdapter(this);
        //If no NfcAdapter, display that the device has no NFC
        if (nfcAdapter == null){
            Toast.makeText(this,"NO NFC Capabilities",
                    Toast.LENGTH_SHORT).show();
        }
        Log.d("nfc_capable", "Phone can use NFC");
        //Create a PendingIntent object so the Android system can
        //populate it with the details of the tag when it is scanned.
        //PendingIntent.getActivity(Context,requestcode(identifier for
        //                           intent),intent,int)
        pendingIntent = PendingIntent.getActivity(this,0,new Intent(this, this.getClass()).addFlags(Intent.FLAG_ACTIVITY_SINGLE_TOP),0);
    }


    @Override
    protected void onNewIntent(Intent intent) {
        super.onNewIntent(intent);
        setIntent(intent);
        resolveIntent(intent);
    }
    public void resolveIntent(Intent newIntent){
        String action = newIntent.getAction();
        Log.d("myTag", action);
        newIntent = new Intent(this, NFC_Info.class);
        if(NfcAdapter.ACTION_TAG_DISCOVERED.equals(action)){
            startActivity(newIntent);
        }
    }
 

И мой манифест проверяет возможности NFC, а также имеет фильтры намерений.

 <?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="com.example.app_2">

    <uses-permission android:name="android.permission.NFC" />
    <uses-feature android:name="android.hardware.nfc" android:required="true" />
    <application
        android:allowBackup="true"
        android:icon="@mipmap/ic_launcher"
        android:label="@string/app_name"
        android:roundIcon="@mipmap/ic_launcher_round"
        android:supportsRtl="true"
        android:theme="@style/Theme.App_2">
        <activity android:name=".graph_trial2"></activity>
        <activity
            android:name=".TrialHeader2"
            android:label="@string/title_activity_trial_header2"
            android:theme="@style/Theme.App_2.NoActionBar" />
        <activity android:name=".NFC_Info" />
        <activity android:name=".MainActivity">
            <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.TAG_DISCOVERED"/>
            </intent-filter>
        </activity>
    </application>

</manifest>
 

Проблема в том, что, когда я открываю приложение, onNewIntent не вызывается, когда мой телефон гудит по NFC, и поэтому ничего не происходит.
Любая помощь в обнаружении NFC будет очень признательна!!