NFC接口適配,讀寫標簽(Note與Galaxy系列)
作者:網(wǎng)絡整理
針對NFC機型,可以對標簽進行讀寫操作。
源碼簡介
針對NFC機型,可以對標簽進行讀寫操作。
源碼運行截圖
y
源碼片段
- /寫入內(nèi)容
- toWBtn=(Button)findViewById(R.id.toWBtn);
- toWBtn.setOnClickListener(new OnClickListener() {
- @Override
- public void onClick(View arg0) {
- // TODO Auto-generated method stub
- Intent intent=new Intent(MainActivity.this,Write2Nfc.class);
- startActivity(intent);
- }
- });
- //NFC適配器,所有的關(guān)于NFC的操作從該適配器進行
- nfcAdapter = NfcAdapter.getDefaultAdapter(this);
- if(!ifNFCUse()){
- return;
- }
- //將被調(diào)用的Intent,用于重復被Intent觸發(fā)后將要執(zhí)行的跳轉(zhuǎn)
- pendingIntent = PendingIntent.getActivity(this, 0, new Intent(this,
- getClass()).addFlags(Intent.FLAG_ACTIVITY_SINGLE_TOP), 0);
- //設(shè)定要過濾的標簽動作,這里只接收ACTION_NDEF_DISCOVERED類型
- ndef = new IntentFilter(NfcAdapter.ACTION_NDEF_DISCOVERED);
- ndef.addCategory("*/*");
- mFilters = new IntentFilter[] { ndef };// 過濾器
- mTechLists = new String[][] { new String[] { NfcA.class.getName() },
- new String[] { NfcF.class.getName() },
- new String[] { NfcB.class.getName() },
- new String[] { NfcV.class.getName() } };// 允許掃描的標簽類型
源碼鏈接:http://down.51cto.com/data/1978596
責任編輯:chenqingxiang
來源:
網(wǎng)絡整理