當前位置: 首頁>>代碼示例>>Java>>正文


Java NdefRecord.getType方法代碼示例

本文整理匯總了Java中android.nfc.NdefRecord.getType方法的典型用法代碼示例。如果您正苦於以下問題:Java NdefRecord.getType方法的具體用法?Java NdefRecord.getType怎麽用?Java NdefRecord.getType使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在android.nfc.NdefRecord的用法示例。


在下文中一共展示了NdefRecord.getType方法的13個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: 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;
}
 
開發者ID:felixb,項目名稱:basscast,代碼行數:20,代碼來源:Stream.java

示例2: 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);
}
 
開發者ID:TapTrack,項目名稱:TappyBLE,代碼行數:22,代碼來源:TcmpMessageDescriptor.java

示例3: 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);
        }
    }
}
 
開發者ID:The-WebOps-Club,項目名稱:saarang-iosched,代碼行數:25,代碼來源:NfcBadgeActivity.java

示例4: 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());
}
 
開發者ID:kemerelab,項目名稱:RodentDBS,代碼行數:21,代碼來源:UnknownRecord.java

示例5: getNdefRecordTypeLength

import android.nfc.NdefRecord; //導入方法依賴的package包/類
private DataReply getNdefRecordTypeLength(int recordNumber) {
    DataReply dataReply = new DataReply();
    int length = 0;
    if (currentTag != null) {
        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.GINGERBREAD_MR1) {
            Ndef ndef = Ndef.get(currentTag);
            if (ndef != null) {
                if (ndef.getCachedNdefMessage() != null)
                    if (ndef.getCachedNdefMessage().getRecords().length > recordNumber) {
                        NdefRecord record = ndef.getCachedNdefMessage().getRecords()[recordNumber];
                        length = record.getType().length;
                    } else {
                        dataReply.setError(RECORD_NOT_FOUND);
                        return dataReply;
                    }
                else {
                    dataReply.setError(RECORD_NOT_FOUND);
                    return dataReply;
                }
            } else {
                dataReply.setError(TAG_READING_ERROR);
                return dataReply;
            }
            try {
                if (ndef != null) ndef.close();
            } catch (IOException e) {
                e.printStackTrace();
            }
        }
    }
    dataReply.setIntegerData(length);
    return dataReply;
}
 
開發者ID:Dnet3,項目名稱:CustomAndroidOneSheeld,代碼行數:34,代碼來源:NfcShield.java

示例6: handleExternalTypeRecord

import android.nfc.NdefRecord; //導入方法依賴的package包/類
private static Pair<String,Boolean> handleExternalTypeRecord(NdefRecord record,
                                                             String[] userSpecifiedTypes,
                                                             String domainForExternalTypes) {
    String typeAsString = new String(record.getType(), UTF8_CHARSET);
    if (recordTypeIsExpected(typeAsString, userSpecifiedTypes, domainForExternalTypes)) {
        return new Pair<>(new String(record.getPayload(), UTF8_CHARSET), true);
    } else {
        return new Pair<>(READ_ERROR_MISMATCH_KEY, false);
    }
}
 
開發者ID:dimagi,項目名稱:commcare-android,代碼行數:11,代碼來源:NdefRecordUtil.java

示例7: parse

import android.nfc.NdefRecord; //導入方法依賴的package包/類
public static ExternalTypeRecord parse(NdefRecord ndefRecord) {
	String domainType = new String(ndefRecord.getType(), Charset.forName("UTF-8"));
	
	int colon = domainType.lastIndexOf(':');
	
	String type;
	String domain;
	if(colon == -1) {
		domain = domainType;
		type = null;
	} else {
		domain = domainType.substring(0, colon);
		if(colon + 1 < domainType.length()) {
			type = domainType.substring(colon + 1);
		} else {
			type = "";
		}
	}

	if(domain.equals(AndroidApplicationRecord.DOMAIN) && type.equals(AndroidApplicationRecord.TYPE)) {
		return new AndroidApplicationRecord(ndefRecord.getPayload());
	}
	
	// see if there is a custom parser
	if(pluginExternalTypeParser != null) {
		if(pluginExternalTypeParser.canParse(domain, type)) {
			ExternalTypeRecord record = pluginExternalTypeParser.parse(domain, type, ndefRecord.getPayload());
			if(record == null) {
				throw new IllegalArgumentException("External Type record " + domainType + " cannot be null");
			}
			return record;
		}
	}
	
	return new GenericExternalTypeRecord(domain, type, ndefRecord.getPayload());
}
 
開發者ID:kemerelab,項目名稱:RodentDBS,代碼行數:37,代碼來源:ExternalTypeRecord.java

示例8: parse

import android.nfc.NdefRecord; //導入方法依賴的package包/類
public static EmptyRecord parse(NdefRecord ndefRecord) {
	// check that type is zero length
	byte[] type = ndefRecord.getType();
	if(type != null && type.length > 0) {
		throw new IllegalArgumentException(EmptyRecord.class.getSimpleName() + " type not expected");
	}

	// check that type is zero length
	byte[] payload = ndefRecord.getPayload();
	if(payload != null && payload.length > 0) {
		throw new IllegalArgumentException(EmptyRecord.class.getSimpleName() + " payload not expected");
	}
	
	return new EmptyRecord();
}
 
開發者ID:kemerelab,項目名稱:RodentDBS,代碼行數:16,代碼來源:EmptyRecord.java

示例9: parseNFCStringPayload

import android.nfc.NdefRecord; //導入方法依賴的package包/類
public static String parseNFCStringPayload(Bundle extras) {

    StringBuilder result = new StringBuilder();

    byte[] nfcID = extras.getByteArray(NfcAdapter.EXTRA_ID);
    if (nfcID != null) {
      result.append("NFC ID: ").append(toHexString(nfcID)).append('\n');
    }

    Tag tag = (Tag) extras.get(NfcAdapter.EXTRA_TAG);
    if (tag != null) {
      result.append(tag).append('\n');
    }

    Parcelable[] messages = extras.getParcelableArray(NfcAdapter.EXTRA_NDEF_MESSAGES);
    if (messages != null) {
      for (Parcelable message : messages) {
        NdefRecord[] records = ((NdefMessage) message).getRecords();
        if (records != null) {
          result.append("NDEF Messages:\n");
          for (NdefRecord record : records) {
            byte[] type = record.getType();
            if (isType(type, NdefRecord.RTD_TEXT)) {
              // Special case: only return text
              return decodeTextPayload(record.getPayload());
            }
            if (isType(type, NdefRecord.RTD_URI)) {
              // Special case: only return URI
              return decodeURIPayload(record.getPayload());
            }
            result.append(' ').append(tnfToName(record.getTnf())).append(" : ")
                .append('(').append(typeToName(type)).append(")\n");
          }
        }
      }
    }

    return result.toString();
  }
 
開發者ID:srowen,項目名稱:zxing-bsplus,代碼行數:40,代碼來源:NFCInterface.java

示例10: handleIntent

import android.nfc.NdefRecord; //導入方法依賴的package包/類
private void handleIntent(Intent intent) {
    if (NfcAdapter.ACTION_NDEF_DISCOVERED.equals(intent.getAction())) {
        Parcelable[] rawMsgs = intent.getParcelableArrayExtra(NfcAdapter.EXTRA_NDEF_MESSAGES);
        if (rawMsgs != null) {
            NdefMessage[] msgs = new NdefMessage[rawMsgs.length];
            for (int i = 0; i < rawMsgs.length; i++) {
                msgs[i] = (NdefMessage) rawMsgs[i];

                NdefRecord[] records = msgs[i].getRecords();
                for(int j = 0; j < records.length; j++) {
                    NdefRecord record = records[j];
                    byte[] typeArray = record.getType();
                    String mimeType = new String(typeArray);
                    if (record.getTnf() == NdefRecord.TNF_MIME_MEDIA && mimeType.equals(Const.ARROW_MIME)) {
                        taggedPerson(new String(record.getPayload()));
                    }
                }

            }
        }
    } else if (Intent.ACTION_VIEW.equals(intent.getAction())){
        if (intent.getData() != null && intent.getDataString().length() > Const.QR_MSG_PREFIX.length()){
            String msg = intent.getDataString().substring(Const.QR_MSG_PREFIX.length());
            taggedPerson(msg);
        }
    }
}
 
開發者ID:gdgjodhpur,項目名稱:gdgapp,代碼行數:28,代碼來源:ArrowActivity.java

示例11: parse

import android.nfc.NdefRecord; //導入方法依賴的package包/類
public static UnsupportedRecord parse(NdefRecord ndefRecord) {
	return new UnsupportedRecord(ndefRecord.getTnf(), ndefRecord.getType(), ndefRecord.getId(), ndefRecord.getPayload());
}
 
開發者ID:kemerelab,項目名稱:RodentDBS,代碼行數:4,代碼來源:UnsupportedRecord.java

示例12: UnsupportedRecord

import android.nfc.NdefRecord; //導入方法依賴的package包/類
public UnsupportedRecord(NdefRecord record) {
	this(record.getTnf(), record.getType(), record.getId(), record.getPayload());
}
 
開發者ID:kemerelab,項目名稱:RodentDBS,代碼行數:4,代碼來源:UnsupportedRecord.java

示例13: parse

import android.nfc.NdefRecord; //導入方法依賴的package包/類
public static MimeRecord parse(NdefRecord ndefRecord) {
	String contentType = new String(ndefRecord.getType(), Charset.forName("US-ASCII")); // http://www.ietf.org/rfc/rfc2046.txt
	
	return new MimeRecord(contentType, ndefRecord.getPayload());
}
 
開發者ID:kemerelab,項目名稱:RodentDBS,代碼行數:6,代碼來源:MimeRecord.java


注:本文中的android.nfc.NdefRecord.getType方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。