Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/193.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
Android 仅在NFC调用时启动活动_Android_Android Activity_Nfc - Fatal编程技术网

Android 仅在NFC调用时启动活动

Android 仅在NFC调用时启动活动,android,android-activity,nfc,Android,Android Activity,Nfc,我的活动A是主要活动,活动B是我在应用程序中使用的另一个活动。现在,我只想在被NFC标签调用时执行应用程序B 我写了一个NFC标签,运行应用程序com.test.NFC)”(这是我的测试应用程序包)。它可以工作,但它运行的是主(活动A),当然,这不是我想要的 如果我使用NFC,我希望主应用程序将是活动B(我重复,仅当我使用NFC运行应用程序时)。有什么办法吗 我尝试使用PlayStore中的Tasker应用程序启动活动,但只有在安装了此应用程序后,它才能工作。如果我卸载它,它将不再工作。只需为您

我的活动A是主要活动,活动B是我在应用程序中使用的另一个活动。现在,我只想在被NFC标签调用时执行应用程序B

我写了一个NFC标签,运行应用程序com.test.NFC)”(这是我的测试应用程序包)。它可以工作,但它运行的是主(活动A),当然,这不是我想要的

如果我使用NFC,我希望主应用程序将是活动B(我重复,仅当我使用NFC运行应用程序时)。有什么办法吗


我尝试使用PlayStore中的Tasker应用程序启动活动,但只有在安装了此应用程序后,它才能工作。如果我卸载它,它将不再工作。

只需为您希望仅在NFC上运行的活动设置意图筛选器,然后在manifest.xml上运行即可

    <activity
        android:name="com.activity.a"
        android:label="@string/app_name"

        android:screenOrientation="portrait" >
        <intent-filter>
            <action android:name="android.intent.action.MAIN" />
            <category android:name="android.intent.category.LAUNCHER" />
        </intent-filter>
    </activity>
    <activity
        android:name="com.activity.b"
        android:screenOrientation="portrait" >
        <intent-filter>
            <action android:name="android.nfc.action.NDEF_DISCOVERED" />
            <category android:name="android.intent.category.DEFAULT" />
            <data
                android:host="ext"
                android:pathPrefix="/com.example:ddcnfc"
                android:scheme="vnd.android.nfc" />
        </intent-filter>
    </activity>
@Override
public void onResume() {
    super.onResume();
    if (NfcAdapter.ACTION_NDEF_DISCOVERED.equals(getIntent().getAction())) {
        //Your initialization goes here
    }
}