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


Java Ndef.getCachedNdefMessage方法代碼示例

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


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

示例1: getNdefUsedSize

import android.nfc.tech.Ndef; //導入方法依賴的package包/類
private DataReply getNdefUsedSize() {
    DataReply dataReply = new DataReply();
    int size = 0;
    if (currentTag != null) {
        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.GINGERBREAD_MR1) {
            Ndef ndef = Ndef.get(currentTag);
            if (ndef != null && ndef.getCachedNdefMessage() != null)
                size = ndef.getCachedNdefMessage().toByteArray().length;
            else {
                dataReply.setError(TAG_READING_ERROR);
                return dataReply;
            }
            try {
                if (ndef != null) ndef.close();
            } catch (IOException e) {
            }
        }
    }
    dataReply.setIntegerData(size);
    return dataReply;
}
 
開發者ID:Dnet3,項目名稱:CustomAndroidOneSheeld,代碼行數:22,代碼來源:NfcShield.java

示例2: nfcRead

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

示例3: doInBackground

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

示例4: getTagText

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

示例5: doInBackground

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

示例6: readTag

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

示例7: doInBackground

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

示例8: doInBackground

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

示例9: doInBackground

import android.nfc.tech.Ndef; //導入方法依賴的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) {
    try {
      tmpPubKey = readKey(ndefRecord);
      return tmpPubKey.toString();
    } catch (UnsupportedEncodingException e) {
      Log.e(TAG, "Unsupported Encoding", e);
    }
  }

  return null;
}
 
開發者ID:masstamike,項目名稱:easypgp,代碼行數:25,代碼來源:NfcActivity.java

示例10: read

import android.nfc.tech.Ndef; //導入方法依賴的package包/類
private void read(Intent intent) {
	Tag tag = intent.getParcelableExtra(NfcAdapter.EXTRA_TAG);
	Ndef ndef = Ndef.get(tag);

	if (ndef == null) {
		Toast.makeText(this, "Read failed", Toast.LENGTH_LONG).show();
	} else {
		// Read tag
		NdefMessage msg;
		msg = ndef.getCachedNdefMessage();
		if (msg == null || msg.getRecords() == null
				|| msg.getRecords()[0] == null
				|| msg.getRecords()[0].getPayload() == null) {
			Toast.makeText(this, "Read failed", Toast.LENGTH_LONG).show();
			return;
		}

		String text = new String(msg.getRecords()[0].getPayload());

		Toast.makeText(this, text, Toast.LENGTH_LONG).show();

	}
}
 
開發者ID:knr1,項目名稱:ch.bfh.mobicomp,代碼行數:24,代碼來源:MainActivity.java

示例11: onTagDiscovered

import android.nfc.tech.Ndef; //導入方法依賴的package包/類
/**
 * NFC
 */
@Override
public void onTagDiscovered(Tag tag) {
    Ndef ndef = Ndef.get(tag);
    NdefMessage message;

    if (ndef != null) {
        message = ndef.getCachedNdefMessage();
    } else {
        return;
    }

    mUrls.clear();

    if (message != null) {
        digUrisInMessage(message);
    }

    // URL一覧の変更をListViewに通知する
    runOnUiThread(new Runnable() {
        @Override
        public void run() {
            mAdapter.notifyDataSetChanged();
        }
    });
}
 
開發者ID:TechBooster,項目名稱:C85-Android-4.4-Sample,代碼行數:29,代碼來源:MainActivity.java

示例12: getNdefRecordCount

import android.nfc.tech.Ndef; //導入方法依賴的package包/類
private DataReply getNdefRecordCount() {
    DataReply dataReply = new DataReply();
    int recordCount = 0;
    if (currentTag != null) {
        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.GINGERBREAD_MR1) {
            Ndef ndef = Ndef.get(currentTag);

            if (ndef != null) {
                if (ndef.getCachedNdefMessage() != null)
                    recordCount = ndef.getCachedNdefMessage().getRecords().length;
                else
                    recordCount = 0;
            } else {
                dataReply.setError(TAG_READING_ERROR);
                return dataReply;
            }
            try {
                if (ndef != null) ndef.close();
            } catch (IOException e) {
                e.printStackTrace();
            }
        }
    }
    if (recordCount > 256) {
        dataReply.setError(INDEX_OUT_OF_BOUNDS);
        recordCount = 256;
    }
    dataReply.setIntegerData(recordCount);
    return dataReply;
}
 
開發者ID:Dnet3,項目名稱:CustomAndroidOneSheeld,代碼行數:31,代碼來源:NfcShield.java

示例13: getNdefRecordTypeLength

import android.nfc.tech.Ndef; //導入方法依賴的package包/類
private DataReply getNdefRecordTypeLength(int recordNumber) {
    DataReply dataReply = new DataReply();
    int length = 0;
    if (currentTag != null) {
        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.GINGERBREAD_MR1) {
            Ndef ndef = Ndef.get(currentTag);
            if (ndef != null) {
                if (ndef.getCachedNdefMessage() != null)
                    if (ndef.getCachedNdefMessage().getRecords().length > recordNumber) {
                        NdefRecord record = ndef.getCachedNdefMessage().getRecords()[recordNumber];
                        length = record.getType().length;
                    } else {
                        dataReply.setError(RECORD_NOT_FOUND);
                        return dataReply;
                    }
                else {
                    dataReply.setError(RECORD_NOT_FOUND);
                    return dataReply;
                }
            } else {
                dataReply.setError(TAG_READING_ERROR);
                return dataReply;
            }
            try {
                if (ndef != null) ndef.close();
            } catch (IOException e) {
                e.printStackTrace();
            }
        }
    }
    dataReply.setIntegerData(length);
    return dataReply;
}
 
開發者ID:Dnet3,項目名稱:CustomAndroidOneSheeld,代碼行數:34,代碼來源:NfcShield.java

示例14: getNdefRecordDataLength

import android.nfc.tech.Ndef; //導入方法依賴的package包/類
private DataReply getNdefRecordDataLength(int recordNumber) {
    DataReply dataReply = new DataReply();
    int length = 0;
    if (currentTag != null) {
        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.GINGERBREAD_MR1) {
            Ndef ndef = Ndef.get(currentTag);
            if (ndef != null) {
                if (ndef.getCachedNdefMessage() != null)
                    if (ndef.getCachedNdefMessage().getRecords().length > recordNumber) {
                        NdefRecord record = ndef.getCachedNdefMessage().getRecords()[recordNumber];
                        length = record.getPayload().length;
                    } else {
                        dataReply.setError(RECORD_NOT_FOUND);
                        return dataReply;
                    }
                else {
                    dataReply.setError(RECORD_NOT_FOUND);
                    return dataReply;
                }
            } else {
                dataReply.setError(TAG_READING_ERROR);
                return dataReply;
            }
            try {
                if (ndef != null) ndef.close();
            } catch (IOException e) {
                e.printStackTrace();
            }
        }
    }
    dataReply.setIntegerData(length);
    return dataReply;
}
 
開發者ID:Dnet3,項目名稱:CustomAndroidOneSheeld,代碼行數:34,代碼來源:NfcShield.java

示例15: doInBackground

import android.nfc.tech.Ndef; //導入方法依賴的package包/類
@Override
protected String doInBackground(Tag... params)
{
    Tag tag = params[0];
    String result;

    mac_cnt = 0;

    Ndef ndef = Ndef.get(tag);

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

    NdefMessage ndefMessage = ndef.getCachedNdefMessage();

    NdefRecord[] records = ndefMessage.getRecords();

    for (NdefRecord record : records) {
        if (record.getTnf() == NdefRecord.TNF_MIME_MEDIA) {
            /* Read the NFC Tags payload */
            readText(record);
        }
    }
    result = "OK";

    return result;
}
 
開發者ID:AinaWireless,項目名稱:PairingExample,代碼行數:30,代碼來源:MainActivity.java


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