10.3.2 基于NFC的点对点通信
如果需要更快捷地在NFC设备中交换数据,可以使用点对点(Peer-to-Peer, P2P)的方式来进行数据传输。
点对点的消息传输,同样也是基于NdefMessage对象来封装数据,示例如下:
//开始写入数据
NdefMessage message=FormatAnMessage();
NfcAdapter.getDefaultAdapter(this).enableForegroundNdefPush(this, message);
…
//停止写入数据
NfcAdapter.getDefaultAdapter(this).disableForegroundNdefPush(this);