我的出发点是在这里https://github.com/rudsonlive/Navigation-Drawer-ActionBarCompat实现一个新的应用与nfc写作支持。如何在碎片中的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();
@Override
protected void onNewIntent(Intent intent) {
// Tag writing mode
if (mWriteMode && NfcAdapter.ACTION_TAG_DISCOVERED.equals(intent.getAction())) {
Tag detectedTag = intent.getParcelableExtra(NfcAdapter.EXTRA_TAG);
if (writeTag(mNdefMessage, detectedTag)) {
Toast.makeText(this, "Writing complete", Toast.LENGTH_LONG).show();
alert.cancel();
}
}
}
可能有人给我一个提醒如上述片段中提到如何写代码?
在此先感谢& SRY,我的英语...