当前位置:网站首页>NFC read / write mode development - book summary
NFC read / write mode development - book summary
2022-06-25 09:53:00 【TowerOs】
Chapter Five: NFC Read write mode
List of articles
Read write mode : The main function is to complete NFC equipment Yes NFC label The operation of
NFC Introduction to read-write mode
- Also known as NFC Reader mode
- Need familiarity NDEF agreement and RTD agreement
Tag Read operations (NDEF data )
- NFC The device is scanned with NDEF When labeling data ,Android It provides support for message parsing
- Learning goals : For any standard Tag Read it
Tag Read operation steps
When NFC The application found a NFC Tag when , It will start the corresponding Activity, stay activity Perform corresponding operations in : For example, using label scheduling system , Define specific IntentFilter
if(NfcAdapter.ACTION_NDEF_DISCOVERED.equals(getIntent().getAction)){
// 1. Definition Tag object
Tag detectedTag = getIntent().getParceableExtra(NfcAdapter.EXTRA_TAG);
// 2. obtain NDEF news
// 3. NDEF Message parsing
// 4. The final real data display and further operation
}
Intent Object can get the following information :
- EXTRA_TAG( necessary ): Representing the scanned label Tag object :
Intent.getParcelableExtra(NfcAdapter.EXTRA_TAG)
obtain - EXTRA_NDEF_MESSAGES( Optional ): Is a machine from the label NDEF An array of messages . This additional message is mandatory in Intent On the object :
Intent.getParcebleArrayExtra(NfcAdapter.EXTRA_NDEF_MESSAGES)
Acquired - EXTRA_ID( Optional ): Low level of label ID
The above information is guaranteed :Activity It was scanned NFC Intent Object started , Can be in onResume() Add the above code to
NDEF Access to information
String action = intent.getAction();
if(action.equals(NfcAdapter.ACYION_NDEF_DISCOVERED)){
NdefMessage[] message = null;
// take Intent The data in is converted to Parcelable data
Parcelable[] rawMsgs = intent.getParcelbleArrayExtra(NfcAdapter.EXTRA_NDEF_MESSAGES);
if(rawMsgs != null){
messages = new NdefMessage[rawMsgs.lenth];
for (int i = 0; i < rawMsgs.length; i++){
// take intent The data in is parsed into the corresponding array
messages[i] = (NdefMesage)rawMsgs[i];
}
}else{
byte[] empty = new byte[];
NdefRecord record = new NdefRecord(NdefRecord.TNF_UNKNOWN, empty, empty, empty);
NdefMessage msg = new NdefMessage(new NdefRecord[]{
record });
messages = new NdefMessage[]{
msg};
}
}else if (action.equals(NfcAdapter.ACYION_TECH_DISCOVERED){
}
else if (action.equals(NfcAdapter.ACYION_TAG_DISCOVERED){
}
else {
}
NDEF Message parsing
//TNF_ABSOLUTE_URI Format analysis
byte[] payLoad = record.getPayload();
Uri uri = Uri.parse(new String(payLoad, Charset.forName("UTF-8")));
record.getType();
record.getId();
recode.getTnf();
// TNF_WELL_KNOWN Format analysis
// Verify that the current record is RTD_URI type
Preconditions.checkArgument(Arrays.equals(record.getType(), NdefRecord.RTD_URI));
// analysis payload data
byte[] payload = record.getPayload();
String prefix = URI_PREFIX_MAP.get(payload[0]);
// Splicing the complete recorded data content
byte[] fulluri = Bytes.concat(prefix.getBytes(
Charset.forName("UTF-8")),
Arrays.copyofRange(payload, 1,1 payload.length));
// Convert to URI Encapsulated object
Uri uri = Uri.parse(new String(fulluri, Charset.forName("UTF-8")));
// Other formats are similar , It's all based on NDEF agreement Data analysis
// P96 Page has a complete code example
For the time being
边栏推荐
- [MySQL learning notes 21] storage engine
- oracle 函数 触发器
- [SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed: unable to get local issuer certificate
- 处理图片类库
- Etcd教程 — 第四章 Etcd集群安全配置
- How do dating applets make millions a year? What is the profit model?
- 链表 删除链表中的节点
- [zufe expense reimbursement] zhecai invoice reimbursement specification (taking Xinmiao reimbursement as an example), which can be passed in one trip at most
- CYCA 2022少儿形体礼仪初级师资班 深圳总部站圆满结束
- What are the PMP scores?
猜你喜欢
CYCA少儿形体礼仪 乐清市培训成果考核圆满落幕
Encoding format for x86
可穿戴设备或将会泄露个人隐私
[competition - Rural Revitalization] experience sharing of Zhejiang Rural Revitalization creative competition
Data-driven anomaly detection and early warning of 21 May Day C
[MySQL learning notes 21] storage engine
manhattan_ Slam environment configuration
字符串 最长公共前缀
Fcpx quickly add subtitles | Final Cut Pro import fcpxml subtitle file does not match the video time? I got it in code
Minio基本使用与原理
随机推荐
An auxiliary MVP architecture project quick development library -mvpfastdagger
Wallys/MULTI-FUNCTION IPQ6010 (IPQ6018 FAMILY) EMBEDDED BOARD WITH ON-BOARD WIFI DUAL BAND DUAL
[competition - Rural Revitalization] experience sharing of Zhejiang Rural Revitalization creative competition
Learning notes of rxjs takeuntil operator
力扣-104. 二叉树的最大深度
Flutter dialog: cupertinoalertdialog
从海量手机号中匹配某一个手机号
PMP考试多少分算通过?
[SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed: unable to get local issuer certificate
Cocopod error failed: undefined method `map 'for nil:nilclass
[matlab] image binarization (imbinarize function)
[zufe expense reimbursement] zhecai invoice reimbursement specification (taking Xinmiao reimbursement as an example), which can be passed in one trip at most
Reasons for Meiye to choose membership system
Is it safe to open an account in a mobile phone or a securities company?
Jetpack compose layout (IV) - constraintlayout
x86电脑上下载debian的arm64的包
Exception: gradle task assemblydebug failed with exit code 1
Minio基本使用与原理
处理图片类库
Is it safe to open an account with Great Wall Securities by mobile phone?