android.nfc.tech.Ndef类的使用及代码示例

x33g5p2x  于2022-01-25 转载在 其他  
字(5.6k)|赞(0)|评价(0)|浏览(113)

本文整理了Java中android.nfc.tech.Ndef类的一些代码示例,展示了Ndef类的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Ndef类的具体详情如下:
包路径:android.nfc.tech.Ndef
类名称:Ndef

Ndef介绍

暂无

代码示例

代码示例来源:origin: commonsguy/cw-omnibus

Ndef ndef=Ndef.get(tag);
 ndef.connect();
  if (!ndef.isWritable()) {
   text="Tag is read-only";
  else if (ndef.getMaxSize()<size) {
   text="Message is too big for tag";
   ndef.writeNdefMessage(msg);
  ndef.close();

代码示例来源:origin: skjolber/ndef-tools-for-android

Ndef ndef = Ndef.get(tag);
if(ndef != null) {
  try {
    if(!ndef.isConnected()) {
      ndef.connect();
    if (!ndef.isWritable()) {
      Log.d(TAG, "Capacity of non-writeable tag is zero");
    int maxSize = ndef.getMaxSize();
    ndef.close();

代码示例来源:origin: RickyYu/Nfc-Android

/**
   * 写数据
   *
   * @param ndefMessage 创建好的NDEF文本数据
   * @param tag         标签
   * @return
   */
  public static boolean writeTag(NdefMessage ndefMessage, Tag tag) {
    try {
      Ndef ndef = Ndef.get(tag);
      ndef.connect();
      ndef.writeNdefMessage(ndefMessage);
      return true;
    } catch (Exception e) {
    }
    return false;
  }
}

代码示例来源:origin: RickyYu/Nfc-Android

@Override
public void onNewIntent(Intent intent) {
  //1.获取Tag对象
  Tag detectedTag = intent.getParcelableExtra(NfcAdapter.EXTRA_TAG);
  //2.获取Ndef的实例
  Ndef ndef = Ndef.get(detectedTag);
  mTagText = ndef.getType() + "\nmaxsize:" + ndef.getMaxSize() + "bytes\n\n";
  readNfcTag(intent);
  mNfcText.setText(mTagText);
}

代码示例来源:origin: skjolber/external-nfc-api

private void ndefWrite() {
  Log.d(TAG, "NDEF write");
  
  Message message = new Message();
  
  UriRecord record = new UriRecord();
  record.setUri(Uri.parse("https://github.com/skjolber/external-nfc-api"));
  
  message.add(record);
  
  try {
    ndef.connect();
    
    ndef.writeNdefMessage(message.getNdefMessage());
    
    ndef.close();
  } catch (Exception e) {
    Log.d(TAG, "Problem writing NDEF message", e);
  }
}

代码示例来源:origin: bparmentier/WiFiKeyShare

public static WifiConfiguration readTag(Tag tag) {
  Ndef ndef = Ndef.get(tag);
  if (ndef == null) {
    Log.d(TAG, "NDEF not supported");
    return null;
  }
  NdefMessage ndefMessage = ndef.getCachedNdefMessage();
  if (ndefMessage == null) {
    Log.d(TAG, "ndefMessage is null");
    return null;
  }
  return NfcUtils.parse(ndefMessage);
}

代码示例来源:origin: skjolber/external-nfc-api

Ndef ndef = Ndef.get(tag);
if(ndef == null) {
  throw new IllegalArgumentException("No NDEF");

代码示例来源:origin: RickyYu/Nfc-Android

@Override
public void onNewIntent(Intent intent) {
  //获取Tag对象
  Tag detectedTag = intent.getParcelableExtra(NfcAdapter.EXTRA_TAG);
  //获取Ndef的实例
  Ndef ndef = Ndef.get(detectedTag);
  mTagText = ndef.getType() + "\n max size:" + ndef.getMaxSize() + " bytes\n\n";
  readNfcTag(intent);
  mNfcText.setText(mTagText);
}

代码示例来源:origin: tyrex-team/senslogs

public void handleTag(Tag tag) {
  Ndef ndef = Ndef.get(tag);
  // NDEF is not supported by this Tag.
  if (ndef == null) return;
  NdefMessage ndefMessage = ndef.getCachedNdefMessage();
  NdefRecord[] records = ndefMessage.getRecords();
  for (NdefRecord ndefRecord : records) {
    if (ndefRecord.getTnf() == NdefRecord.TNF_WELL_KNOWN) {
      try {
        broadcastText(readText(ndefRecord));
      } catch (UnsupportedEncodingException ignored) {
      }
    }
  }
}

代码示例来源:origin: skjolber/external-nfc-api

this.ndef = Ndef.get(tag);

代码示例来源:origin: commonsguy/cw-omnibus

Ndef ndef=Ndef.get(tag);
 ndef.connect();
  if (!ndef.isWritable()) {
   text=host.getString(R.string.tag_is_read_only);
  else if (ndef.getMaxSize() < size) {
   text=host.getString(R.string.message_is_too_big_for_tag);
   ndef.writeNdefMessage(msg);
   text=host.getString(R.string.success);
  ndef.close();

代码示例来源:origin: RickyYu/Nfc-Android

/**
   * 写入标签
   *
   * @param message
   * @param tag
   * @return
   */
  public static boolean writeTag(NdefMessage message, Tag tag) {
    int size = message.toByteArray().length;
    try {
      Ndef ndef = Ndef.get(tag);
      if (ndef != null) {
        ndef.connect();
        if (!ndef.isWritable()) {
          return false;
        }
        if (ndef.getMaxSize() < size) {
          return false;
        }
        ndef.writeNdefMessage(message);
        return true;
      }
    } catch (Exception e) {
    }
    return false;
  }
}

代码示例来源:origin: Mobisocial/EasyNFC

private int writeTag(Tag tag, NdefMessage message) {
  try {
    int size = message.toByteArray().length;
    Ndef ndef = Ndef.get(tag);
    if (ndef != null) {
      ndef.connect();
      if (!ndef.isWritable()) {
        Log.w(TAG, "Tag is read-only.");
        return OnTagWriteListener.WRITE_ERROR_READ_ONLY;
      if (ndef.getMaxSize() < size) {
        Log.d(TAG, "Tag capacity is " + ndef.getMaxSize() + " bytes, message is " +
            size + " bytes.");
        return OnTagWriteListener.WRITE_ERROR_CAPACITY;
      ndef.writeNdefMessage(message);
      return OnTagWriteListener.WRITE_OK;
    } else {

代码示例来源:origin: RickyYu/Nfc-Android

try {
  Ndef ndef = Ndef.get(tag);
    ndef.connect();
    if (!ndef.isWritable()) {
      return;
    if (ndef.getMaxSize() < size) {
      return;
    ndef.writeNdefMessage(ndefMessage);
    Toast.makeText(this, "写入成功", Toast.LENGTH_SHORT).show();
  } else { //当我们买回来的NFC标签是没有格式化的,或者没有分区的执行此步

代码示例来源:origin: RickyYu/Nfc-Android

try {
  Ndef ndef = Ndef.get(tag);
    ndef.connect();
    if (!ndef.isWritable()) {
      return;
    if (ndef.getMaxSize() < size) {
      return;
    ndef.writeNdefMessage(ndefMessage);
    Toast.makeText(this, "写入成功", Toast.LENGTH_SHORT).show();
  } else { //当我们买回来的NFC标签是没有格式化的,或者没有分区的执行此步

代码示例来源:origin: bparmentier/WiFiKeyShare

Ndef ndef = Ndef.get(tag);
if (ndef != null) {
  ndef.connect();
  if (!ndef.isWritable()) {
    Log.w(TAG, "Tag not writable");
    return false;
  int ndefMaxSize = ndef.getMaxSize();
  if (messageSize > ndefMaxSize) {
    } else {
      Log.d(TAG, "Writing tag without AAR");
      ndef.writeNdefMessage(newMessage);
      return true;
  ndef.writeNdefMessage(message);
  return true;
} else {

代码示例来源:origin: skjolber/ndef-tools-for-android

Ndef ndef = Ndef.get(tag);
if(ndef != null) {
  try {
    Log.d(TAG, "Write formatted tag");
    ndef.connect();
    if (!ndef.isWritable()) {
      Log.d(TAG, "Tag is not writeable");
    if (ndef.getMaxSize() < rawMessage.toByteArray().length) {
      Log.d(TAG, "Tag size is too small, have " + ndef.getMaxSize() + ", need " + rawMessage.toByteArray().length);
      writeNdefTooSmall(rawMessage.toByteArray().length, ndef.getMaxSize());
    ndef.writeNdefMessage(rawMessage);
  } finally {
    try {
      ndef.close();
    } catch (IOException e) {

相关文章