Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/233.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

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/joomla/2.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 Intent_Android Viewpager_Fragment_Nfc - Fatal编程技术网

Android 如何在片段中的nfc标记上写入数据?

Android 如何在片段中的nfc标记上写入数据?,android,android-intent,android-viewpager,fragment,nfc,Android,Android Intent,Android Viewpager,Fragment,Nfc,我的出发点是在这里实现一个具有nfc编写支持的新应用程序 现在我想实现在nfc标签上写入数据。因此,我对不同类型的数据使用不同的片段(例如,一个片段在nfc标签上写入联系人数据,下一个片段在nfc标签上写入特定的应用程序数据,等等) 对于另一个应用程序,我成功地实现了这一点,但是对于设置带有片段的应用程序,我失败了 这就是我在活动中实现标记编写的方式。显示AlertDialog以通知用户接近标签并处理特定意图 enableTagWriteMode(); AlertDialog.Builder a

我的出发点是在这里实现一个具有nfc编写支持的新应用程序

现在我想实现在nfc标签上写入数据。因此,我对不同类型的数据使用不同的片段(例如,一个片段在nfc标签上写入联系人数据,下一个片段在nfc标签上写入特定的应用程序数据,等等)

对于另一个应用程序,我成功地实现了这一点,但是对于设置带有片段的应用程序,我失败了

这就是我在活动中实现标记编写的方式。显示AlertDialog以通知用户接近标签并处理特定意图

enableTagWriteMode();
AlertDialog.Builder ad = new AlertDialog.Builder(NfcDialogActivity.this).setTitle("Approach Tag").setOnCancelListener(
    new DialogInterface.OnCancelListener() {
        @Override
        public void onCancel(DialogInterface dialog) {
            disableTagWriteMode();
        }
    });
alert = ad.create();
alert.show();

有人能给我一个建议,如何在一个片段中写上面提到的标签吗


提前感谢&sry为我提供的英语…

您必须从活动中授权您的意图,以便通过您的片段进行处理。用于获取NFC意图的onNewIntent()仅适用于活动。因此,当发生NFC意图时,您必须确保在片段准备就绪时将其发送到片段(例如,通过从片段中获取getActivity().getIntent()的意图)。

谢谢您的建议!我发现有必要实现onNewIntent()方法,如

@Override
public void onNewIntent(Intent intent) {
    setIntent(intent);
}

你是在活动中只保留这一部分还是NFC的所有其他部分?
@Override
public void onNewIntent(Intent intent) {
    setIntent(intent);
}