当前位置: 首页>>代码示例>>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;未经允许,请勿转载。