一、Android 4.0提供的Demo
public class Beam extends Activity implements CreateNdefMessageCallback,
OnNdefPushCompleteCallback {
NfcAdapter mNfcAdapter;
TextView mInfoText;
private static final int MESSAGE_SENT = 1;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
mInfoText = (TextView) findViewById(R.id.textView);
mNfcAdapter = NfcAdapter.getDefaultAdapter(this); //实例化NFC设备
if (mNfcAdapter == null) {
mInfoText = (TextView) findViewById(R.id.textView);
mInfoText.setText("NFC is not available on this device.");
}
mNfcAdapter.setNdefPushMessageCallback(this, this); //注册NDEF回调消息
mNfcAdapter.setOnNdefPushCompleteCallback(this, this);
}