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


Java NdefMessage.getRecords方法代碼示例

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


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

示例1: tryUpdateIntentFromBeam

import android.nfc.NdefMessage; //導入方法依賴的package包/類
/**
 * Checks to see if the activity's intent ({@link android.app.Activity#getIntent()}) is
 * an NFC intent that the app recognizes. If it is, then parse the NFC message and set the
 * activity's intent (using {@link Activity#setIntent(android.content.Intent)}) to something
 * the app can recognize (i.e. a normal {@link Intent#ACTION_VIEW} intent).
 */
public static void tryUpdateIntentFromBeam(Activity activity) {
    Intent originalIntent = activity.getIntent();
    if (NfcAdapter.ACTION_NDEF_DISCOVERED.equals(originalIntent.getAction())) {
        Parcelable[] rawMsgs = originalIntent.getParcelableArrayExtra(
                NfcAdapter.EXTRA_NDEF_MESSAGES);
        NdefMessage msg = (NdefMessage) rawMsgs[0];
        // Record 0 contains the MIME type, record 1 is the AAR, if present.
        // In iosched, AARs are not present.
        NdefRecord mimeRecord = msg.getRecords()[0];
        if (ScheduleContract.makeContentItemType(
                ScheduleContract.Sessions.CONTENT_TYPE_ID).equals(
                new String(mimeRecord.getType()))) {
            // Re-set the activity's intent to one that represents session details.
            Intent sessionDetailIntent = new Intent(Intent.ACTION_VIEW,
                    Uri.parse(new String(mimeRecord.getPayload())));
            activity.setIntent(sessionDetailIntent);
        }
    }
}
 
開發者ID:dreaminglion,項目名稱:iosched-reader,代碼行數:26,代碼來源:BeamUtils.java

示例2: extractMimePayload

import android.nfc.NdefMessage; //導入方法依賴的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;
}
 
開發者ID:guodroid,項目名稱:okwallet,代碼行數:12,代碼來源:Nfc.java

示例3: parse

import android.nfc.NdefMessage; //導入方法依賴的package包/類
/**
 * Parse an NDEF message and return the corresponding Wi-Fi configuration
 *
 * Source: http://androidxref.com/6.0.1_r10/xref/packages/apps/Nfc/src/com/android/nfc/NfcWifiProtectedSetup.java
 *
 * @param message the NDEF message to parse
 * @return a WifiConfiguration extracted from the NDEF message
 */
private static WifiConfiguration parse(NdefMessage message) {
    NdefRecord[] records = message.getRecords();
    for (NdefRecord record : records) {
        if (new String(record.getType()).equals(NFC_TOKEN_MIME_TYPE)) {
            ByteBuffer payload = ByteBuffer.wrap(record.getPayload());
            while (payload.hasRemaining()) {
                short fieldId = payload.getShort();
                short fieldSize = payload.getShort();
                if (fieldId == CREDENTIAL_FIELD_ID) {
                    return parseCredential(payload, fieldSize);
                } else {
                    payload.position(payload.position() + fieldSize);
                }
            }
        }
    }
    return null;
}
 
開發者ID:bparmentier,項目名稱:WiFiKeyShare,代碼行數:27,代碼來源:NfcUtils.java

示例4: parseNdefMessage

import android.nfc.NdefMessage; //導入方法依賴的package包/類
private void parseNdefMessage(final Intent intent) {
    Parcelable[] rawMsgs = intent.getParcelableArrayExtra(
            NfcAdapter.EXTRA_NDEF_MESSAGES);
    Log.d(TAG, "#msgs: " + rawMsgs.length);
    for (Parcelable rawMsg : rawMsgs) {
        NdefMessage msg = (NdefMessage) rawMsg;
        Log.d(TAG, "#records: " + msg.getRecords().length);
        for (NdefRecord record : msg.getRecords()) {
            try {
                mStream = new Stream(record);
                return;
            } catch (Exception e) {
                Log.e(TAG, "NDEF record is not a stream", e);
            }
        }
    }
    throw new IllegalArgumentException("Invalid NDEF message");
}
 
開發者ID:felixb,項目名稱:basscast,代碼行數:19,代碼來源:EditStreamActivity.java

示例5: parseNdefFoundResponse

import android.nfc.NdefMessage; //導入方法依賴的package包/類
private static String parseNdefFoundResponse(Context ctx, NdefFoundResponse resp) {
    NdefMessage msg = resp.getMessage();
    NdefRecord[] records = msg.getRecords();
    if(records.length == 0) {
        return ctx.getString(R.string.ndef_no_record);
    }
    else if (records.length == 1) {
        return String.format(ctx.getString(R.string.ndef_found_response_single_record),
                ByteUtils.bytesToHex(resp.getTagCode()),
                parseTagType(ctx, resp.getTagType()),
                parseNdefRecord(ctx, records[0]));
    }
    else {
        return String.format(ctx.getString(R.string.ndef_found_response_multi_record),
                ByteUtils.bytesToHex(resp.getTagCode()),
                parseTagType(ctx, resp.getTagType()),
                parseNdefRecord(ctx, records[0]));
    }
}
 
開發者ID:TapTrack,項目名稱:TappyBLE,代碼行數:20,代碼來源:TcmpMessageDescriptor.java

示例6: nfcRead

import android.nfc.NdefMessage; //導入方法依賴的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;

}
 
開發者ID:tawaasalage,項目名稱:RxBluetoothAuto,代碼行數:21,代碼來源:Home.java

示例7: doInBackground

import android.nfc.NdefMessage; //導入方法依賴的package包/類
@Override
protected NFCTag doInBackground(Intent... params) {
    Intent intent = params[0];

    Tag tag = intent.getParcelableExtra(NfcAdapter.EXTRA_TAG);
    Ndef ndef = Ndef.get(tag);

    if (ndef == null) {
        return null;
    }

    NdefMessage ndefMessage = ndef.getCachedNdefMessage();

    if(ndefMessage != null) {
        NdefRecord[] records = ndefMessage.getRecords();
        for (NdefRecord ndefRecord : records) {
            try {
                return new NFCTag(ndefRecord).decode();
            } catch (UnsupportedEncodingException e) {
                Log.e("NFC", "Unsupported Encoding", e);
            }
        }
    }

    return null;
}
 
開發者ID:wesleydebruijn,項目名稱:android-nfc-wrapper,代碼行數:27,代碼來源:NFCReadTask.java

示例8: getTagText

import android.nfc.NdefMessage; //導入方法依賴的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;
}
 
開發者ID:The-Scrum-Masters,項目名稱:archive-carro-inteligente,代碼行數:27,代碼來源:NFCHandler.java

示例9: doInBackground

import android.nfc.NdefMessage; //導入方法依賴的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;
}
 
開發者ID:legendmohe,項目名稱:LEHomeMobile_android,代碼行數:26,代碼來源:NfcReadNdefAsyncTask.java

示例10: toNfcMessage

import android.nfc.NdefMessage; //導入方法依賴的package包/類
/**
 * Converts android.nfc.NdefMessage to mojo NfcMessage
 */
public static NfcMessage toNfcMessage(NdefMessage ndefMessage)
        throws UnsupportedEncodingException {
    NdefRecord[] ndefRecords = ndefMessage.getRecords();
    NfcMessage nfcMessage = new NfcMessage();
    List<NfcRecord> nfcRecords = new ArrayList<NfcRecord>();

    for (int i = 0; i < ndefRecords.length; i++) {
        if ((ndefRecords[i].getTnf() == NdefRecord.TNF_EXTERNAL_TYPE)
                && (Arrays.equals(ndefRecords[i].getType(), WEBNFC_URN.getBytes("UTF-8")))) {
            nfcMessage.url = new String(ndefRecords[i].getPayload(), "UTF-8");
            continue;
        }

        NfcRecord nfcRecord = toNfcRecord(ndefRecords[i]);
        if (nfcRecord != null) nfcRecords.add(nfcRecord);
    }

    nfcMessage.data = new NfcRecord[nfcRecords.size()];
    nfcRecords.toArray(nfcMessage.data);
    return nfcMessage;
}
 
開發者ID:mogoweb,項目名稱:365browser,代碼行數:25,代碼來源:NfcTypeConverter.java

示例11: readTag

import android.nfc.NdefMessage; //導入方法依賴的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

示例12: tryUpdateIntentFromBeam

import android.nfc.NdefMessage; //導入方法依賴的package包/類
/**
 * Checks to see if the activity's intent ({@link android.app.Activity#getIntent()}) is
 * an NFC intent that the app recognizes. If it is, then parse the NFC message and set the
 * activity's intent (using {@link Activity#setIntent(android.content.Intent)}) to something
 * the app can recognize (i.e. a normal {@link Intent#ACTION_VIEW} intent).
 */
public static void tryUpdateIntentFromBeam(Activity activity) {
    Intent originalIntent = activity.getIntent();
    if (NfcAdapter.ACTION_NDEF_DISCOVERED.equals(originalIntent.getAction())) {
        Parcelable[] rawMsgs = originalIntent.getParcelableArrayExtra(
                NfcAdapter.EXTRA_NDEF_MESSAGES);
        NdefMessage msg = (NdefMessage) rawMsgs[0];
        // Record 0 contains the MIME type, record 1 is the AAR, if present.
        // In iosched, AARs are not present.
        NdefRecord mimeRecord = msg.getRecords()[0];
        if (ScheduleContract.Sessions.CONTENT_ITEM_TYPE.equals(
                new String(mimeRecord.getType()))) {
            // Re-set the activity's intent to one that represents session details.
            Intent sessionDetailIntent = new Intent(Intent.ACTION_VIEW,
                    Uri.parse(new String(mimeRecord.getPayload())));
            activity.setIntent(sessionDetailIntent);
        }
    }
}
 
開發者ID:The-WebOps-Club,項目名稱:saarang-iosched,代碼行數:25,代碼來源:BeamUtils.java

示例13: doInBackground

import android.nfc.NdefMessage; //導入方法依賴的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;
}
 
開發者ID:mofosyne,項目名稱:NFCMessageBoard,代碼行數:26,代碼來源:MainScreen.java

示例14: doInBackground

import android.nfc.NdefMessage; //導入方法依賴的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;
}
 
開發者ID:hkboy,項目名稱:NFCPoC,代碼行數:26,代碼來源:MainActivity.java

示例15: getBeamedLyrics

import android.nfc.NdefMessage; //導入方法依賴的package包/類
@TargetApi(14)
private Lyrics getBeamedLyrics(Intent intent) {
    Parcelable[] rawMsgs = intent.getParcelableArrayExtra(NfcAdapter.EXTRA_NDEF_MESSAGES);
    // only one message sent during the beam
    if (rawMsgs != null && rawMsgs.length > 0) {
        NdefMessage msg = (NdefMessage) rawMsgs[0];
        // record 0 contains the MIME type, record 1 is the AAR, if present
        NdefRecord[] records = msg.getRecords();
        if (records.length > 0) {
            try {
                return Lyrics.fromBytes(records[0].getPayload());
            } catch (IOException | ClassNotFoundException e) {
                e.printStackTrace();
            }
        }
    }
    return null;
}
 
開發者ID:QuickLyric,項目名稱:QuickLyric,代碼行數:19,代碼來源:MainActivity.java


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