Android实现读取NFC卡卡号示例,具体如下:
1.权限
android:name="android.hardware.nfc"
android:required="true" />
2.注册(静态)
3.Activity
初始化
//初始化NfcAdapter
mNfcAdapter = NfcAdapter.getDefaultAdapter(this);
// 初始化PendingIntent,当有NFC设备连接上的时候,就交给当前Activity处理
pi = PendingIntent.getActivity(this, 0, new Intent(this, getClass())
.addFlags(Intent.FLAG_ACTIVITY_SINGLE_TOP), 0);
启动
@Override
protected void onResume() {
super.onResume();
mNfcAdapter.enableForegroundDispatch(this, pi, null, null); //启动
}
获取数据
@Override
protected void onNewIntent(Intent intent) {
super.onNewIntent(intent);
// 当前app正在前端界面运行,这个时候有intent发送过来,那么系统就会调用onNewIntent回调方法,将intent传送过来
// 我们只需要