本文整理匯總了Java中android.nfc.NdefRecord.getTnf方法的典型用法代碼示例。如果您正苦於以下問題:Java NdefRecord.getTnf方法的具體用法?Java NdefRecord.getTnf怎麽用?Java NdefRecord.getTnf使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類android.nfc.NdefRecord
的用法示例。
在下文中一共展示了NdefRecord.getTnf方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: 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;
}
示例2: 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;
}
示例3: 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;
}
示例4: parseNdefRecord
import android.nfc.NdefRecord; //導入方法依賴的package包/類
private static String parseNdefRecord(Context ctx, NdefRecord record) {
if(record.getTnf() == NdefRecord.TNF_WELL_KNOWN) {
if(Arrays.equals(record.getType(),NdefRecord.RTD_URI)) {
return parseWellKnownUriRecord(ctx,record);
}
else if (Arrays.equals(record.getType(),NdefRecord.RTD_TEXT)) {
return parseWellKnownTextRecord(ctx, record);
}
else {
return parseGenericNdefRecord(ctx,record);
}
}
else {
return parseGenericNdefRecord(ctx,record);
}
}
示例5: parseTnf
import android.nfc.NdefRecord; //導入方法依賴的package包/類
private static String parseTnf(Context ctx, NdefRecord record) {
short tnf = record.getTnf();
switch(tnf) {
case NdefRecord.TNF_ABSOLUTE_URI:
return ctx.getString(R.string.tnf_abs_uri);
case NdefRecord.TNF_EMPTY:
return ctx.getString(R.string.tnf_empty);
case NdefRecord.TNF_EXTERNAL_TYPE:
return ctx.getString(R.string.tnf_external);
case NdefRecord.TNF_MIME_MEDIA:
return ctx.getString(R.string.tnf_mime_media);
case NdefRecord.TNF_UNCHANGED:
return ctx.getString(R.string.tnf_unchanged);
case NdefRecord.TNF_WELL_KNOWN:
return ctx.getString(R.string.tnf_well_known);
default:
return ctx.getString(R.string.tnf_unknown);
}
}
示例6: parseType
import android.nfc.NdefRecord; //導入方法依賴的package包/類
private static String parseType(Context ctx, NdefRecord record) {
byte[] type = record.getType();
if(Arrays.equals(type, NdefRecord.RTD_URI))
return ctx.getString(R.string.rtd_uri);
else if(Arrays.equals(type,NdefRecord.RTD_ALTERNATIVE_CARRIER))
return ctx.getString(R.string.rtd_alt_carrier);
else if(Arrays.equals(type,NdefRecord.RTD_HANDOVER_CARRIER))
return ctx.getString(R.string.rtd_handover_carrier);
else if(Arrays.equals(type,NdefRecord.RTD_HANDOVER_REQUEST))
return ctx.getString(R.string.rtd_handover_request);
else if(Arrays.equals(type,NdefRecord.RTD_HANDOVER_SELECT))
return ctx.getString(R.string.rtd_handover_select);
else if(Arrays.equals(type,NdefRecord.RTD_SMART_POSTER))
return ctx.getString(R.string.rtd_smart_poster);
else if(Arrays.equals(type,NdefRecord.RTD_TEXT))
return ctx.getString(R.string.rtd_text);
else if (record.getTnf() == NdefRecord.TNF_MIME_MEDIA)
return new String(type);
else
return ByteUtils.bytesToHex(type);
}
示例7: nfcRead
import android.nfc.NdefRecord; //導入方法依賴的package包/類
public String nfcRead(Tag t)
{
Tag tag = t;
Ndef ndef = Ndef.get(tag);
if (ndef == null) {
return null;
}
NdefMessage ndefMessage = ndef.getCachedNdefMessage();
NdefRecord[] records = ndefMessage.getRecords();
for (NdefRecord ndefRecord : records)
{
if (ndefRecord.getTnf() == NdefRecord.TNF_WELL_KNOWN && Arrays.equals(ndefRecord.getType(), NdefRecord.RTD_TEXT))
{
try {return readText(ndefRecord);} catch (UnsupportedEncodingException e) {}
}
}
return null;
}
示例8: getTagText
import android.nfc.NdefRecord; //導入方法依賴的package包/類
public String getTagText() throws Exception
{
if (tag == null)
{
throw new Exception("Please call handle new read as tag is null");
}
Ndef ndef = Ndef.get(tag);
NdefMessage ndefMessage = ndef.getCachedNdefMessage();
NdefRecord[] records = ndefMessage.getRecords();
for (NdefRecord ndefRecord : records)
{
if (ndefRecord.getTnf() == NdefRecord.TNF_WELL_KNOWN && Arrays.equals(ndefRecord.getType(), NdefRecord.RTD_TEXT))
{
try
{
return readText(ndefRecord);
}
catch (UnsupportedEncodingException e)
{
Toast.makeText(activity, "Unsupported encoding", Toast.LENGTH_SHORT).show();
}
}
}
return null;
}
示例9: doInBackground
import android.nfc.NdefRecord; //導入方法依賴的package包/類
@Override
protected ArrayList<String> doInBackground(Tag... params) {
Tag tag = params[0];
Ndef ndef = Ndef.get(tag);
if (ndef == null) {
// NDEF is not supported by this Tag.
return null;
}
ArrayList<String> results = new ArrayList<>();
NdefMessage ndefMessage = ndef.getCachedNdefMessage();
NdefRecord[] records = ndefMessage.getRecords();
for (NdefRecord ndefRecord : records) {
if (ndefRecord.getTnf() == NdefRecord.TNF_WELL_KNOWN && Arrays.equals(ndefRecord.getType(), NdefRecord.RTD_TEXT)) {
try {
results.add(readText(ndefRecord));
} catch (UnsupportedEncodingException e) {
Log.e(TAG, "Unsupported Encoding", e);
}
}
}
return results;
}
示例10: toNfcRecord
import android.nfc.NdefRecord; //導入方法依賴的package包/類
/**
* Converts android.nfc.NdefRecord to mojo NfcRecord
*/
private static NfcRecord toNfcRecord(NdefRecord ndefRecord)
throws UnsupportedEncodingException {
switch (ndefRecord.getTnf()) {
case NdefRecord.TNF_EMPTY:
return createEmptyRecord();
case NdefRecord.TNF_MIME_MEDIA:
return createMIMERecord(
new String(ndefRecord.getType(), "UTF-8"), ndefRecord.getPayload());
case NdefRecord.TNF_ABSOLUTE_URI:
return createURLRecord(ndefRecord.toUri());
case NdefRecord.TNF_WELL_KNOWN:
return createWellKnownRecord(ndefRecord);
}
return null;
}
示例11: 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);
}
}
}
示例12: doInBackground
import android.nfc.NdefRecord; //導入方法依賴的package包/類
@Override
protected String doInBackground(Tag... params) {
Tag tag = params[0];
Ndef ndef = Ndef.get(tag);
if (ndef == null) {
// NDEF is not supported by this Tag.
return null;
}
NdefMessage ndefMessage = ndef.getCachedNdefMessage();
NdefRecord[] records = ndefMessage.getRecords();
for (NdefRecord ndefRecord : records) {
if (ndefRecord.getTnf() == NdefRecord.TNF_WELL_KNOWN && Arrays.equals(ndefRecord.getType(), NdefRecord.RTD_TEXT)) {
try {
return readText(ndefRecord);
} catch (UnsupportedEncodingException e) {
//Log.e(TAG, "Unsupported Encoding", e);
}
}
}
return null;
}
示例13: doInBackground
import android.nfc.NdefRecord; //導入方法依賴的package包/類
@Override
protected String doInBackground(Tag... params) {
Tag tag = params[0];
Ndef ndef = Ndef.get(tag);
if (ndef == null) {
// NDEF is not supported by this Tag.
return null;
}
NdefMessage ndefMessage = ndef.getCachedNdefMessage();
NdefRecord[] records = ndefMessage.getRecords();
for (NdefRecord ndefRecord : records) {
if (ndefRecord.getTnf() == NdefRecord.TNF_WELL_KNOWN && Arrays.equals(ndefRecord.getType(), NdefRecord.RTD_TEXT)) {
try {
return readText(ndefRecord);
} catch (UnsupportedEncodingException e) {
Log.e(TAG, "Unsupported Encoding", e);
}
}
}
return null;
}
示例14: getRecords
import android.nfc.NdefRecord; //導入方法依賴的package包/類
public static List<ParsedNdefRecord> getRecords(NdefRecord[] records) {
List<ParsedNdefRecord> elements = new ArrayList<ParsedNdefRecord>();
for (NdefRecord record : records) {
if(record.getTnf() != NdefRecord.TNF_WELL_KNOWN){
Log.e("TNF_NOT_KNOWN", "This tag has a TNF not known!");
return elements;
}
// if(record.getType().equals(NdefRecord.RTD_URI)) {
// elements.add(UriRecord.parse(record));
// }
// if (record.getType().equals(NdefRecord.RTD_TEXT)) {
elements.add(TextRecord.parse(record));
// }
// if (record.getType().equals(NdefRecord.RTD_SMART_POSTER)) {
// elements.add(SmartPoster.parse(record));
// }
}
return elements;
}
示例15: parse
import android.nfc.NdefRecord; //導入方法依賴的package包/類
/**
* 解析NdefRecord中Uri數據
*
* @param record
* @return
*/
public static Uri parse(NdefRecord record) {
short tnf = record.getTnf();
if (tnf == NdefRecord.TNF_WELL_KNOWN) {
return parseWellKnown(record);
} else if (tnf == NdefRecord.TNF_ABSOLUTE_URI) {
return parseAbsolute(record);
}
throw new IllegalArgumentException("Unknown TNF " + tnf);
}