本文整理匯總了Java中android.nfc.NdefRecord.getPayload方法的典型用法代碼示例。如果您正苦於以下問題:Java NdefRecord.getPayload方法的具體用法?Java NdefRecord.getPayload怎麽用?Java NdefRecord.getPayload使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類android.nfc.NdefRecord
的用法示例。
在下文中一共展示了NdefRecord.getPayload方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: getTextFromNdefRecord
import android.nfc.NdefRecord; //導入方法依賴的package包/類
private String getTextFromNdefRecord(NdefRecord ndefRecord)
{
String content = null;
try
{
byte[] payload = ndefRecord.getPayload();
String encoding = ((payload[0] & 128) == 0) ? "UTF-8" : "UTf-8";
int languageSize = payload[0] & 0063;
content = new String(payload, languageSize+1, payload.length - languageSize - 1, encoding);
}
catch (UnsupportedEncodingException e)
{
Log.e("createTextRecord", e.getMessage());
}
return content;
}
示例2: parseTextRecord
import android.nfc.NdefRecord; //導入方法依賴的package包/類
private String parseTextRecord(NdefRecord record){
String response=null;
// 驗證TNF是否為TNF_WELL_KNOWN
if(record.getTnf()!=NdefRecord.TNF_WELL_KNOWN) {
System.out.println("不是TNF_WELL_KNOW");
return null;
}
byte[] payload=record.getPayload();
Byte statusByte=payload[0];
String textCoding=((statusByte&0x80)==0)?"utf-8":"utf-16";
int codeLength=statusByte&0x3f;
try{
response=new String(payload,codeLength+1,payload.length-codeLength-1,textCoding);
}
catch(UnsupportedEncodingException e){
Toast.makeText(getApplicationContext(),e.getMessage(),Toast.LENGTH_LONG).show();
}
return response;
}
示例3: extractMimePayload
import android.nfc.NdefRecord; //導入方法依賴的package包/類
@Nullable
public static byte[] extractMimePayload(final String mimeType, final NdefMessage message) {
final byte[] mimeBytes = mimeType.getBytes(Charsets.US_ASCII);
for (final NdefRecord record : message.getRecords()) {
if (record.getTnf() == NdefRecord.TNF_MIME_MEDIA && Arrays.equals(record.getType(), mimeBytes))
return record.getPayload();
}
return null;
}
示例4: parseNdefRecord
import android.nfc.NdefRecord; //導入方法依賴的package包/類
private static byte[] parseNdefRecord(final NdefRecord record) {
if (record.getTnf() != NdefRecord.TNF_EXTERNAL_TYPE) {
throw new IllegalArgumentException("Invalid TNF: " + record.getTnf());
}
final byte[] type = record.getType();
if (type == null) {
throw new NullPointerException("Type must not be null");
}
final String typeString = new String(type);
if (!typeString.equalsIgnoreCase(BuildConfig.APPLICATION_ID + ":stream")) {
throw new IllegalArgumentException("Invalid type: " + typeString);
}
final byte[] bytes = record.getPayload();
if (bytes == null) {
throw new NullPointerException("Payload must not be null");
}
return bytes;
}
示例5: readText
import android.nfc.NdefRecord; //導入方法依賴的package包/類
private String readText(NdefRecord record) throws UnsupportedEncodingException
{
/*
* See NFC forum specification for "Text Record Type Definition" at 3.2.1
*
* http://www.nfc-forum.org/specs/
*
* bit_7 defines encoding
* bit_6 reserved for future use, must be 0
* bit_5..0 length of IANA language code
*/
byte[] payload = record.getPayload();
// Get the Text Encoding
String textEncoding = ((payload[0] & 128) == 0) ? "UTF-8" : "UTF-16";
// Get the Language Code
int languageCodeLength = payload[0] & 0063;
// String languageCode = new String(payload, 1, languageCodeLength, "US-ASCII");
// e.g. "en"
// Get the Text
return new String(payload, languageCodeLength + 1, payload.length - languageCodeLength - 1, textEncoding);
}
示例6: readText
import android.nfc.NdefRecord; //導入方法依賴的package包/類
private String readText(NdefRecord record) throws UnsupportedEncodingException {
byte[] payload = record.getPayload();
// Get the Text Encoding
String textEncoding = null;
if ((payload[0] & 128) == 0) {
textEncoding = "UTF-8";
} else {
textEncoding = "UTF-16";
}
// Get the Language Code
int languageCodeLength = payload[0] & 0063;
// Get the Text
return new String(payload, languageCodeLength + 1, payload.length - languageCodeLength - 1, textEncoding);
}
示例7: readText
import android.nfc.NdefRecord; //導入方法依賴的package包/類
private String readText(NdefRecord record) throws UnsupportedEncodingException {
/*
* See NFC forum specification for "Text Record Type Definition" at 3.2.1
*
* http://www.nfc-forum.org/specs/
*
* bit_7 defines encoding
* bit_6 reserved for future use, must be 0
* bit_5..0 length of IANA language code
*/
byte[] payload = record.getPayload();
// Get the Text Encoding
String textEncoding = ((payload[0] & 128) == 0) ? "UTF-8" : "UTF-16";
// Get the Language Code
int languageCodeLength = payload[0] & 0063;
// String languageCode = new String(payload, 1, languageCodeLength, "US-ASCII");
// e.g. "en"
// Get the Text
return new String(payload, languageCodeLength + 1, payload.length - languageCodeLength - 1, textEncoding);
}
示例8: readTag
import android.nfc.NdefRecord; //導入方法依賴的package包/類
private void readTag(Tag t) {
byte[] id = t.getId();
// get NDEF tag details
Ndef ndefTag = Ndef.get(t);
// get NDEF message details
NdefMessage ndefMesg = ndefTag.getCachedNdefMessage();
if (ndefMesg == null) {
return;
}
NdefRecord[] ndefRecords = ndefMesg.getRecords();
if (ndefRecords == null) {
return;
}
for (NdefRecord record : ndefRecords) {
short tnf = record.getTnf();
String type = new String(record.getType());
if (tnf == NdefRecord.TNF_WELL_KNOWN && Arrays.equals(type.getBytes(), NdefRecord.RTD_URI)) {
String url = new String(record.getPayload());
recordBadge(url);
}
}
}
示例9: readText
import android.nfc.NdefRecord; //導入方法依賴的package包/類
private String readText(NdefRecord record) throws UnsupportedEncodingException {
/*
* See NFC forum specification for "Text Record Type Definition" at 3.2.1
*
* http://www.nfc-forum.org/specs/
*
* bit_7 defines encoding
* bit_6 reserved for future use, must be 0
* bit_5..0 length of IANA language code
*/
byte[] payload = record.getPayload();
// Get the Text Encoding
String textEncoding = ((payload[0] & 128) == 0) ? "UTF-8" : "UTF-16";
// Get the Language Code
int languageCodeLength = payload[0] & 0063;
// String languageCode = new String(payload, 1, languageCodeLength, "US-ASCII");
// e.g. "en"
// Get the Text
return new String(payload, languageCodeLength + 1, payload.length - languageCodeLength - 1, textEncoding);
}
示例10: readText
import android.nfc.NdefRecord; //導入方法依賴的package包/類
private String readText(NdefRecord record) throws UnsupportedEncodingException {
/*
* See NFC forum specification for "Text Record Type Definition" at 3.2.1
*
* http://www.nfc-forum.org/specs/
*
* bit_7 defines encoding
* bit_6 reserved for future use, must be 0
* bit_5..0 length of IANA language code
*/
byte[] payload = record.getPayload();
// Get the Text Encoding
String textEncoding = ((payload[0] & 128) == 0) ? "UTF-8" : "UTF-16"; //Don't pay attention to this, it just works �\_(?)_/�
// Get the Language Code
int languageCodeLength = payload[0] & 0063;
// String languageCode = new String(payload, 1, languageCodeLength, "US-ASCII");
// e.g. "en"
// Get the Text
return new String(payload, languageCodeLength + 1, payload.length - languageCodeLength - 1, textEncoding);
}
示例11: readText
import android.nfc.NdefRecord; //導入方法依賴的package包/類
private String readText(NdefRecord record) throws UnsupportedEncodingException {
/*
* See NFC forum specification for "Text Record Type Definition" at 3.2.1
*
* http://www.nfc-forum.org/specs/
*
* bit_7 defines encoding
* bit_6 reserved for future use, must be 0
* bit_5..0 length of IANA language code
*/
byte[] payload = record.getPayload();
// Get the Text Encoding
String textEncoding = ((payload[0] & 128) == 0) ? "UTF-8" : "UTF-16";
// Get the Language Code
int languageCodeLength = payload[0] & 0063;
// String languageCode = new String(payload, 1, languageCodeLength, "US-ASCII");
// e.g. "en"
// Get the Text
return new String(payload, languageCodeLength + 1, payload.length - languageCodeLength - 1, textEncoding);
}
示例12: parse
import android.nfc.NdefRecord; //導入方法依賴的package包/類
public static Record parse(NdefRecord ndefRecord) {
/**
The value 0x05 (Unknown) SHOULD be used to indicate that the type of the payload is
unknown. This is similar to the "application/octet-stream" media type defined by MIME [RFC
2046]. When used, the TYPE_LENGTH field MUST be zero and thus the TYPE field is omitted
from the NDEF record. Regarding implementation, it is RECOMMENDED that an NDEF parser
receiving an NDEF record of this type, without further context to its use, provides a mechanism
for storing but not processing the payload (see section 4.2).
*/
// check that type is zero length
byte[] type = ndefRecord.getType();
if(type != null && type.length > 0) {
throw new IllegalArgumentException("Record type not expected");
}
return new UnknownRecord(ndefRecord.getPayload());
}
示例13: parse
import android.nfc.NdefRecord; //導入方法依賴的package包/類
public static TextRecord parse(NdefRecord record) {
String languageCode, text;
byte[] payload = record.getPayload();
String textEncoding = ((payload[0] & 0200) == 0) ? "UTF-8" : "UTF-16";
int languageCodeLength = payload[0] & 0077;
try {
languageCode = new String(payload, 1, languageCodeLength, "US-ASCII");
text = new String(payload, languageCodeLength + 1, payload.length
- languageCodeLength - 1, textEncoding);
} catch (UnsupportedEncodingException e) {
// should never happen unless we get a malformed tag.
throw new IllegalArgumentException(e);
}
return new TextRecord(languageCode, text);
}
示例14: parseNdefRecord
import android.nfc.NdefRecord; //導入方法依賴的package包/類
public static SmartPosterRecord parseNdefRecord(NdefRecord ndefRecord) throws FormatException {
byte[] payload = ndefRecord.getPayload();
normalizeMessageBeginEnd(payload);
SmartPosterRecord smartPosterRecord = new SmartPosterRecord();
if(payload.length > 0) {
List<Record> records = Message.parseNdefMessage(payload);
for (Record record : records) {
if (record instanceof UriRecord) {
smartPosterRecord.setUri((UriRecord)record);
}
else if (record instanceof TextRecord) {
smartPosterRecord.setTitle((TextRecord)record);
}
else if (record instanceof ActionRecord) {
smartPosterRecord.setAction((ActionRecord)record);
}
}
}
return smartPosterRecord;
}
示例15: parseNdefRecord
import android.nfc.NdefRecord; //導入方法依賴的package包/類
@SuppressLint("NewApi")
public static UriRecord parseNdefRecord(NdefRecord ndefRecord) {
if (android.os.Build.VERSION.SDK_INT >= 16) {
return new UriRecord(ndefRecord.toUri());
} else {
byte[] payload = ndefRecord.getPayload();
if (payload.length < 2) {
return null;
}
// payload[0] contains the URI Identifier Code, as per
// NFC Forum "URI Record Type Definition" section 3.2.2.
int prefixIndex = (payload[0] & (byte)0xFF);
if (prefixIndex < 0 || prefixIndex >= URI_PREFIX_MAP.length) {
return null;
}
String prefix = URI_PREFIX_MAP[prefixIndex];
String suffix = new String(Arrays.copyOfRange(payload, 1, payload.length),
Charset.forName("UTF-8"));
return new UriRecord(Uri.parse(prefix + suffix));
}
}