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 
Full Snippet Info
7
CodeRank
Stop searching for code, let great code find you!  Add Codota to your java IDE
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);
Full Snippet Info
7
CodeRank
Stop searching for code, let great code find you!  Add Codota to your java IDE
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
Stop searching for code, let great code find you!  Add Codota to your java IDE
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();
Full Snippet Info
7
CodeRank
Stop searching for code, let great code find you!  Add Codota to your java IDE
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();
Full Snippet Info
6
CodeRank
Stop searching for code, let great code find you!  Add Codota to your java IDE

Related Android NdefRecord Questions & Answers:

See Code Examples for Android NdefRecord Methods: