NFC Demo MockNdefMessages

没有接触过NFC的知识,一下子看这个Demo肯定挺吃力的,最近我就到了NFC forum里面下载了NFC Text tag, URI tag, Smart Poster, NDEF这四份文档,一一区把其读懂。我把我读懂的结果和大家分享一下,对于NFC的message,以后有空我会把这四份英文的文档翻译成中文。^_^

/*
 * Copyright (C) 2010 The Android Open Source Project
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package com.example.android.nfc.simulator;

/**
 * This class provides a list of fake NFC Ndef format Tags.
 */
public class MockNdefMessages {

	/**
	 * A Smart Poster containing a URL and no text.
	 */
	public static final byte[] SMART_POSTER_URL_NO_TEXT = new byte[] {
		    //Message Header=11010 001(MB ME CF SR IL INF(001))
			(byte) 0xd1, //MB=1 ME=1 CF=0 SR=1 IL=0 INF=001
			
			(byte) 0x02,//Type length=2
			(byte) 0x0f, // Payload length=15				
			//Type=SP-->This tag type is Smart Poster
			(byte) 0x53,//S
			(byte) 0x70,//P	
			
			//Payload 
			(byte) 0xd1,	//11010 001(MB ME CF SR IL INF(001))	
			(byte) 0x01, //Type length=1
			(byte) 0x0b, //Payload length=11			
			(byte) 0x55, //	type=U-->record type is URI
			//subPayload
			(byte) 0x01,//URI Identifier code=1-->http:www.
			//google.com
			(byte) 0x67,(byte) 0x6f,(byte) 0x6f, (byte) 0x67, (byte) 0x6c, (byte) 0x65, (byte) 0x2e,
			(byte) 0x63,(byte) 0x6f, (byte) 0x6d };
			
			

	/**
	 * A plain text tag in english.
	 */
	public static final byte[] ENGLISH_PLAIN_TEXT = new byte[] {
			(byte) 0xd1, //11010 001(MB ME CF SR IL INF(001))
			(byte) 0x01,//Type length=11
			(byte) 0x1c,//Payload length=28
			(byte) 0x54,// Type=T-->record type is TEXT
			(byte) 0x02,//Status byte 00000010 -->UTF-8, Language codes length=2
			
			//Language Codes="en"
			(byte) 0x65,	// e	
			(byte) 0x6e,	// n
			
			// Some random english text
			(byte) 0x53, (byte) 0x6f, (byte) 0x6d, (byte) 0x65, (byte) 0x20,
			(byte) 0x72, (byte) 0x61, (byte) 0x6e, (byte) 0x64, (byte) 0x6f,
			(byte) 0x6d, (byte) 0x20, (byte) 0x65, (byte) 0x6e, (byte) 0x67,
			(byte) 0x6c, (byte) 0x69, (byte) 0x73, (byte) 0x68, (byte) 0x20,
			(byte) 0x74, (byte) 0x65, (byte) 0x78, (byte) 0x74, (byte) 0x2e };

	/**
	 * Smart Poster containing a URL and Text.
	 */
	public static final byte[] SMART_POSTER_URL_AND_TEXT = new byte[] {
			(byte) 0xd1,  //11010 001(MB ME CF SR IL INF(001))
			(byte) 0x02,//Type length=2
			(byte) 0x1c,//Payload length=28
			
			//Type=SP
			(byte) 0x53, //S
			(byte) 0x70,	//p
			
			//------Text record----------------------------------------//
			(byte) 0x91, //10010001(MB ME CF SR IL INF(001)) 
			(byte) 0x01, //Type length=1
			(byte) 0x09,//Payload length=9
	
			(byte) 0x54, 		//Type=T-->TEXT

			(byte) 0x02,//Status byte 00000010 -->UTF-8, Language codes length=2
			
			//Language Codes="en"
			(byte) 0x65,	//n
			(byte) 0x6e,	//e
			
			// Google
			(byte) 0x47, (byte) 0x6f, (byte) 0x6f, (byte) 0x67, (byte) 0x6c,(byte) 0x65,
			//------Text record----------------------------------------//
			
			//---URI record------------------------------------------//
			(byte) 0x51, //01010001(MB ME CF SR IL INF(001)) 
			
			(byte) 0x01, //Type length=1
			(byte) 0x0b,//Payload length=11
			(byte) 0x55,			// U
			(byte) 0x01,	// http://www.
			// google.com
			(byte) 0x67, (byte) 0x6f, (byte) 0x6f, (byte) 0x67, (byte) 0x6c,
			(byte) 0x65, (byte) 0x2e, (byte) 0x63, (byte) 0x6f, (byte) 0x6d };
	
	
	

	/**
	 * All the mock Ndef tags.
	 */
	public static final byte[][] ALL_MOCK_MESSAGES = new byte[][] {
			SMART_POSTER_URL_NO_TEXT, ENGLISH_PLAIN_TEXT,
			SMART_POSTER_URL_AND_TEXT };
}

你可能感兴趣的:(apache,android,Google)