简体   繁体   English

NFC Smartposter拨打号码

[英]NFC Smartposter to Dial a number

i want to create a NFC SmartPoster which dial a number with Action Record type "act". 我想创建一个NFC SmartPoster,该号码可以拨打操作记录类型为“ act”的号码。 Can anyone tell how to get Action Record type "act" in android from packet and check whether packet contains Action Record type "act" or not. 谁能告诉我如何从数据包中获取操作记录类型“ act”,并检查数据包是否包含操作记录类型“ act”。 Below is packet i have created. 以下是我创建的数据包。

/**
 * Smart Poster containing a Telephone number and Action record type.
 */

public static final byte[] SMART_POSTER_Dial_Number =
    new byte[] {
    // SP type record
    (byte) 0xd1, (byte) 0x02, (byte) 0x26, (byte) 0x53, (byte) 0x70,
 // Call type record
    (byte) 0xd1, (byte) 0x01, (byte) 0x0e, (byte) 0x55, (byte) 0x05, (byte) 0x2b,
    (byte) 0x39, (byte) 0x31, (byte) 0x38, (byte) 0x38, (byte) 0x37, (byte) 0x32,
    (byte) 0x37, (byte) 0x34, (byte) 0x33, (byte) 0x39, (byte) 0x33, (byte) 0x39, 

    // Action type record
    (byte) 0x11, (byte) 0x03, (byte) 0x01, (byte) 0x61, (byte) 0x63, (byte) 0x74,
    (byte) 0x00,
 // Text type record with 'T'
    (byte) 0x91, (byte) 0x01, (byte) 0x09, (byte) 0x54, (byte) 0x02, (byte) 'C',
    (byte) 'a', (byte) 'l', (byte) 'l', (byte) 'i', (byte) 'n', (byte) 'g', (byte) '.'


     };

Please help.. 请帮忙..

When you receive an NDEF message in your Activity via an ACTION_NDEF_DISCOVERED intent, you can parse and check the contents for a SmartPoster record with an embedded 'act' record as follows: 当您通过ACTION_NDEF_DISCOVERED意向在Activity收到NDEF消息时,可以解析并检查具有嵌入式“行为”记录的SmartPoster记录的内容,如下所示:

Intent intent = getIntent();
final Parcelable[] rawMsgs = intent.getParcelableArrayExtra(NfcAdapter.EXTRA_NDEF_MESSAGES);
NdefMessage mesg = (NdefMessage) rawMsgs[0]; // in theory there can be more messages

// let's inspect the first record only
NdefRecord[] record = mesg.getRecords()[0];
byte[] type = record.getType();

// check if it is a SmartPoster
byte[] smartPoster = { 'S', 'p'};
if (Arrays.equals(smartPoster, type) {
  byte[] payload = record.getPayload();

  // try to parse the payload as NDEF message
  NdefMessage n;
  try {
    n = new NdefMessage(payload);
  } catch (FormatException e) {
    return; // not an NDEF message, we're done
  }

  // try to find the 'act' record
  NdefRecord[] recs = n.getRecords();
  byte[] act = { 'a', 'c', 't' };
  for (NdefRecord r : recs) {
    if (Arrays.equals(act, r.getType()) {
      ... // found it; do your thing!
      return;
    }
  }
}
return; // nothing found 

BTW: You will find that there are a couple of format errors in the example message in your question: the first byte of the Uri record should be 0x81 and the first byte of the Text record should be 0x51 . 顺便说一句:您会发现问题示例消息中存在一些格式错误:Uri记录的第一个字节应为0x81 ,而Text记录的第一个字节应为0x51

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM