Android NdefRecord - top ranked examples from Open Source projects

These code examples were ranked by Codota’s semantic indexing as the best open source examples for Android NdefRecord class.

This code example shows how to use the following methods:getPayload, getTnf, getType
        return mLanguageCode;
    } 
 
    // TODO: deal with text fields which span multiple NdefRecords 
    public static TextRecord parse(NdefRecord record) {
        Preconditions.checkArgument(record.getTnf() == NdefRecord.TNF_WELL_KNOWN);
        Preconditions.checkArgument(Arrays.equals(record.getType(), NdefRecord.RTD_TEXT));
        try { 
 
            byte[] payload = record.getPayload();
            Preconditions.checkArgument(payload.length > 0);
 
            /* 
             * payload[0] contains the "Status Byte Encodings" field, per 
             * the NFC Forum "Text Record Type Definition" section 3.2.1. 
             * 
             * bit7 is the Text Encoding Field. 
             * 
             * if (Bit_7 == 0): The text is encoded in UTF-8 
             * if (Bit_7 == 1): The text is encoded in UTF16 
7
CodeRank
Contextual code suggestions in your IDE  Get Codota for Java
This code example shows how to use the following methods:getPayload, getType
        return new UriRecord(uri);
    } 
 
    /** Parse an well known URI record */ 
    private static UriRecord parseWellKnown(NdefRecord record) {
        Preconditions.checkArgument(Arrays.equals(record.getType(), NdefRecord.RTD_URI));
        byte[] payload = record.getPayload();
        /* 
         * payload[0] contains the URI Identifier Code, per the 
         * NFC Forum "URI Record Type Definition" section 3.2.2. 
         * 
         * payload[1]...payload[payload.length - 1] contains the rest of 
         * the URI. 
         */ 
        String prefix = URI_PREFIX_MAP.get(payload[0]);
        byte[] fullUri =
            Bytes.concat(prefix.getBytes(Charset.forName("UTF-8")), Arrays.copyOfRange(payload, 1,
                payload.length));
        Uri uri = Uri.parse(new String(fullUri, Charset.forName("UTF-8")));
        return new UriRecord(uri);
7
CodeRank
Contextual code suggestions in your IDE  Get Codota for Java
This code example shows how to use the following methods:getPayload, getTnf, getType
		mNdefExchange = ndefExchange;
	} 
 
	@Override 
	public boolean supportsRequest(NdefRecord handoverRequest) {
	    short tnf = handoverRequest.getTnf();
		if (tnf != NdefRecord.TNF_ABSOLUTE_URI && (tnf != NdefRecord.TNF_WELL_KNOWN &&
		        !Arrays.equals(handoverRequest.getType(), NdefRecord.RTD_URI))) {
			return false; 
		} 
		Uri uri;
		try { 
		    uri= NdefFactory.parseUri(handoverRequest);
		} catch (FormatException e) {
		    return false; 
		} 
		String scheme = uri.getScheme();
		return (scheme != null && scheme.equals("ndef+bluetooth"));
	} 
	 

7
CodeRank
Contextual code suggestions in your IDE  Get Codota for Java
This code example shows how to use the following methods:getPayload, getTnf, getType
        } 
        return wrappedNdef;
    } 
 
    public static final Uri parseUri(NdefRecord record) throws FormatException {
        int tnf = record.getTnf();
        if (tnf == NdefRecord.TNF_ABSOLUTE_URI) {
            return Uri.parse(new String(record.getType()));
        } 
        if (tnf == NdefRecord.TNF_WELL_KNOWN &&
                Arrays.equals(NdefRecord.RTD_URI, record.getType())) {
            byte[] payload = record.getPayload();
            int pre = (int)payload[0];
            if (!(pre >= 0 && pre < URI_PREFIXES.length)) {
                throw new FormatException("Unknown uri prefix: " + pre);
            } 
            String prefix = URI_PREFIXES[pre];
            String uriStr = new StringBuilder()
                .append(prefix).append(new String(payload, 1, payload.length - 1))
                .toString();
7
CodeRank
Contextual code suggestions in your IDE  Get Codota for Java
This code example shows how to use the following methods:
    protected void onNewIntent(Intent intent) {
        switch (mTagToWrite) {
        case TAG_ALLOW:
            Tag tagFromIntent = intent.getParcelableExtra(NfcAdapter.EXTRA_TAG);
 
            NdefRecord record = new NdefRecord(NdefRecord.TNF_MIME_MEDIA,
                    "text/x-su-a".getBytes(),
                    new byte[0], 
                    PreferenceManager.getDefaultSharedPreferences(this)
                            .getString("pin", "").getBytes());
            NdefMessage message = new NdefMessage(new NdefRecord[] {record });
 
            Ndef ndef = Ndef.get(tagFromIntent);
            if (ndef != null) {
                if (!ndef.isWritable()) {
                    Toast.makeText(this, "Tag not writeable", Toast.LENGTH_SHORT).show();
                    return; 
                } 
                 
                int maxSize = ndef.getMaxSize();
6
CodeRank
Contextual code suggestions in your IDE  Get Codota for Java
This code example shows how to use the following methods:getPayload, getType
        return new UriRecord(uri);
    } 
 
    /** Parse an well known URI record */ 
    private static UriRecord parseWellKnown(NdefRecord record) {
        Preconditions.checkArgument(Arrays.equals(record.getType(), NdefRecord.RTD_URI));
        byte[] payload = record.getPayload();
        /* 
         * payload[0] contains the URI Identifier Code, per the 
         * NFC Forum "URI Record Type Definition" section 3.2.2. 
         * 
         * payload[1]...payload[payload.length - 1] contains the rest of 
         * the URI. 
         */ 
        String prefix = URI_PREFIX_MAP.get(payload[0]);
        byte[] fullUri =
            Bytes.concat(prefix.getBytes(Charset.forName("UTF-8")), Arrays.copyOfRange(payload, 1,
                payload.length));
        Uri uri = Uri.parse(new String(fullUri, Charset.forName("UTF-8")));
        return new UriRecord(uri);
6
CodeRank
Contextual code suggestions in your IDE  Get Codota for Java
This code example shows how to use the following methods:getPayload, getTnf, getType
        this.setExtNamespace(extNamespace);
        this.setPayload(payload);
    } 
 
    public static ExternalNdefRecord fromNdefRecord(NdefRecord ndefRecord) {
        Preconditions.checkNotNull(ndefRecord);
 
        short tnf = ndefRecord.getTnf();
        Preconditions.checkArgument(tnf == NdefRecord.TNF_EXTERNAL_TYPE);
 
        try { 
            String type = new String(ndefRecord.getType(), Charset.forName("UTF-8"));
            byte[] payload = ndefRecord.getPayload();
 
            return new ExternalNdefRecord(type, payload);
 
        } catch (Exception exception) {
            throw new IllegalArgumentException(exception);
        } 
    } 
6
CodeRank
Contextual code suggestions in your IDE  Get Codota for Java
This code example shows how to use the following methods:getPayload, getTnf, getType
    public static boolean isImage(NdefRecord record) {
        try { 
            parse(record);
            return true; 
        } catch (IllegalArgumentException e) {
            return false; 
        } 
    } 
 
    public static NdefRecord newImageRecord(Bitmap bitmap) {
        ByteArrayOutputStream out = new ByteArrayOutputStream();
        bitmap.compress(Bitmap.CompressFormat.JPEG, 100, out);
        byte[] content = out.toByteArray();
        return MimeRecord.newMimeRecord("image/jpeg", content);
    } 
} 
6
CodeRank
Contextual code suggestions in your IDE  Get Codota for Java
This code example shows how to use the following methods:getPayload, getTnf, getType
			throw new IllegalArgumentException(exception);
		} 
	} 
	 
	public static TextNdefRecord fromNdefRecord(NdefRecord ndefRecord) {
		Preconditions.checkNotNull(ndefRecord);
		Preconditions.checkArgument(ndefRecord.getTnf() == NdefRecord.TNF_WELL_KNOWN);
		Preconditions.checkArgument(Arrays.equals(ndefRecord.getType(), NdefRecord.RTD_TEXT));
		 
		try { 
			byte[] payload = ndefRecord.getPayload();
			 
			String textEncoding = ((payload[0] & 0200) == 0) ? "UTF-8" : "UTF-16";
            int languageCodeLength = payload[0] & 0077;
 
            String languageCode = new String(payload, 1, languageCodeLength, "US-ASCII");
            String text = new String(payload,
                    languageCodeLength + 1,
                    payload.length - languageCodeLength - 1,
                    textEncoding);
6
CodeRank
Contextual code suggestions in your IDE  Get Codota for Java
This code example shows how to use the following methods:getPayload, getTnf, getType
    public String getSnippet(Context context, Locale locale) {
        return mType;
    } 
 
    public static MimeRecord parse(NdefRecord record) {
        Preconditions.checkArgument(record.getTnf() == NdefRecord.TNF_MIME_MEDIA);
        String type = new String(record.getType(), Charset.forName("US-ASCII"));
        byte[] payload = record.getPayload();
        return new MimeRecord(type, payload);
    } 
 
    public static boolean isMime(NdefRecord record) {
        try { 
            parse(record);
            return true; 
        } catch (IllegalArgumentException e) {
            return false; 
        } 
    } 
 
6
CodeRank
Contextual code suggestions in your IDE  Get Codota for Java

Related Android NdefRecord Questions & Answers:

See Code Examples for Android NdefRecord Methods: