本文整理匯總了Java中android.nfc.Tag類的典型用法代碼示例。如果您正苦於以下問題:Java Tag類的具體用法?Java Tag怎麽用?Java Tag使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。
Tag類屬於android.nfc包,在下文中一共展示了Tag類的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: onNewIntent
import android.nfc.Tag; //導入依賴的package包/類
@Override
public void onNewIntent(Intent intent)
{
String action = intent.getAction();
// Log.i("!intent! ", action);
Tag tag = intent.getParcelableExtra(NfcAdapter.EXTRA_TAG);
byte[] id = tag.getId();
String serialNumber = bytesToHex(id);
WritableMap idData = Arguments.createMap();
idData.putString("id", serialNumber);
sendEvent(this.reactContext, "NFCCardID", idData);
}
示例2: onTagDiscovered
import android.nfc.Tag; //導入依賴的package包/類
@Override
public void onTagDiscovered(final Tag tag) {
Log.d(TAG, "Tag found: " + tag.toString());
Log.d(TAG, "Id: " + HexStrings.toHexString(tag.getId()));
for (String tech: tag.getTechList()) {
Log.d(TAG, "Tech: " + tech);
}
if (Arrays.asList(tag.getTechList()).contains("android.nfc.tech.IsoDep")) {
IsoDepApduInterface apduInterface;
try {
apduInterface = new IsoDepApduInterface(IsoDep.get(tag));
} catch (IOException e) {
fail(e.getMessage());
e.printStackTrace();
return;
}
dispatchLoadTask(apduInterface);
}
}
示例3: formatTag
import android.nfc.Tag; //導入依賴的package包/類
private void formatTag(Tag tag, NdefMessage ndefMessage)
{
try
{
NdefFormatable ndefFormatable = NdefFormatable.get(tag);
if (ndefFormatable == null)
{
Toast.makeText(this, "Tag is not formatable", Toast.LENGTH_LONG).show();
}
ndefFormatable.connect();
ndefFormatable.format(ndefMessage);
ndefFormatable.close();
}
catch (Exception e)
{
Log.e("formatTag", e.getMessage());
}
}
示例4: onNewIntent
import android.nfc.Tag; //導入依賴的package包/類
@Override
public void onNewIntent(Intent intent) {
Tag tag = intent.getParcelableExtra(NfcAdapter.EXTRA_TAG);
String[] techList = tag.getTechList();
boolean haveMifareUltralight = false;
for (String tech : techList) {
if (tech.indexOf("MifareUltralight") >= 0) {
haveMifareUltralight = true;
break;
}
}
if (!haveMifareUltralight) {
Toast.makeText(this, "不支持MifareUltralight數據格式", Toast.LENGTH_SHORT).show();
return;
}
writeTag(tag);
}
示例5: onNewIntent
import android.nfc.Tag; //導入依賴的package包/類
@Override
public void onNewIntent(Intent intent) {
Tag tag = intent.getParcelableExtra(NfcAdapter.EXTRA_TAG);
String[] techList = tag.getTechList();
boolean haveMifareUltralight = false;
for (String tech : techList) {
if (tech.indexOf("MifareUltralight") >= 0) {
haveMifareUltralight = true;
break;
}
}
if (!haveMifareUltralight) {
Toast.makeText(this, "不支持MifareUltralight數據格式", Toast.LENGTH_SHORT).show();
return;
}
String data = readTag(tag);
if (data != null)
Toast.makeText(this, data, Toast.LENGTH_SHORT).show();
}
示例6: onNewIntent
import android.nfc.Tag; //導入依賴的package包/類
public void onNewIntent(Intent intent) {
Tag detectedTag = intent.getParcelableExtra(NfcAdapter.EXTRA_TAG);
NdefMessage ndefMessage = new NdefMessage(new NdefRecord[]{createUriRecord(mUri)});
boolean result = writeTag(ndefMessage, detectedTag);
if (result) {
Toast.makeText(this, "寫入成功", Toast.LENGTH_SHORT).show();
} else {
Toast.makeText(this, "寫入失敗", Toast.LENGTH_SHORT).show();
}
}
示例7: writeTag
import android.nfc.Tag; //導入依賴的package包/類
/**
* 寫入標簽
*
* @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;
}
示例8: connect
import android.nfc.Tag; //導入依賴的package包/類
private void connect(final CallbackContext callbackContext) {
cordova.getThreadPool().execute(new Runnable() {
@Override
public void run() {
if (getIntent() == null) { // Lost Tag
clean(callbackContext, "No tag available.");
return;
}
final Tag tag = savedIntent.getParcelableExtra(NfcAdapter.EXTRA_TAG);
if (tag == null) {
clean(callbackContext, "No tag available.");
return;
}
try {
Log.i(TAG, "Tag is: " + tag);
mifareUltralight.connect(tag);
callbackContext.success();
} catch (final Exception e) {
clean(callbackContext, e);
}
}
});
}
開發者ID:RoopeHakulinen,項目名稱:cordova-plugin-mifare-ultralight,代碼行數:25,代碼來源:CordovaPluginMifareUltralight.java
示例9: unlock
import android.nfc.Tag; //導入依賴的package包/類
private void unlock(final CallbackContext callbackContext, final int pin) {
cordova.getThreadPool().execute(new Runnable() {
@Override
public void run() {
if (getIntent() == null) { // Lost Tag
clean(callbackContext, "No tag available.");
return;
}
final Tag tag = savedIntent.getParcelableExtra(NfcAdapter.EXTRA_TAG);
if (tag == null) {
clean(callbackContext, "No tag available.");
return;
}
try {
mifareUltralight.unlockWithPin(pin);
callbackContext.success();
} catch (final Exception e) {
clean(callbackContext, e);
}
}
});
}
開發者ID:RoopeHakulinen,項目名稱:cordova-plugin-mifare-ultralight,代碼行數:24,代碼來源:CordovaPluginMifareUltralight.java
示例10: parseMessage
import android.nfc.Tag; //導入依賴的package包/類
private void parseMessage() {
cordova.getThreadPool().execute(new Runnable() {
@Override
public void run() {
Log.d(TAG, "parseMessage " + getIntent());
Intent intent = getIntent();
String action = intent.getAction();
Log.d(TAG, "action " + action);
if (action == null) {
return;
}
Tag tag = intent.getParcelableExtra(NfcAdapter.EXTRA_TAG);
if (action.equals(NfcAdapter.ACTION_TAG_DISCOVERED)) {
fireTagEvent(tag, "mifareTagDiscovered");
}
setIntent(new Intent());
}
});
}
開發者ID:RoopeHakulinen,項目名稱:cordova-plugin-mifare-ultralight,代碼行數:21,代碼來源:CordovaPluginMifareUltralight.java
示例11: eraseTag
import android.nfc.Tag; //導入依賴的package包/類
private void eraseTag(CallbackContext callbackContext) throws JSONException {
Tag tag = savedIntent.getParcelableExtra(NfcAdapter.EXTRA_TAG);
NdefRecord[] records = {
new NdefRecord(NdefRecord.TNF_EMPTY, new byte[0], new byte[0], new byte[0])
};
writeNdefMessage(new NdefMessage(records), tag, callbackContext);
}
示例12: onActivityNewIntent
import android.nfc.Tag; //導入依賴的package包/類
/**
* To be executed on onNewIntent of activity
* @param intent
*/
public void onActivityNewIntent(Intent intent) {
// TODO Check if the following line has any use
// activity.setIntent(intent);
if (textToWrite == null)
readTagFromIntent(intent);
else {
Tag tag = intent.getParcelableExtra(NfcAdapter.EXTRA_TAG);
try {
writeTag(activity, tag, textToWrite);
onTagWriteListener.onTagWritten();
} catch (NFCWriteException exception) {
onTagWriteErrorListener.onTagWriteError(exception);
} finally {
textToWrite = null;
}
}
}
示例13: handleIntent
import android.nfc.Tag; //導入依賴的package包/類
private void handleIntent(Intent intent)
{
String action = intent.getAction();
if (NfcAdapter.ACTION_NDEF_DISCOVERED.equals(action))
{
String type = intent.getType();
if (type.equals("application/vnd.bluetooth.ep.oob"))
{
Tag tag = intent.getParcelableExtra(NfcAdapter.EXTRA_TAG);
new NdefReaderTask().execute(tag);
}
else
{
Log.d(TAG, "Wrong mime type: " + type);
}
}
}
示例14: resolveIntent
import android.nfc.Tag; //導入依賴的package包/類
private void resolveIntent(Intent intent) {
String action = intent.getAction();
if (NfcAdapter.ACTION_TAG_DISCOVERED.equals(action)
|| NfcAdapter.ACTION_TECH_DISCOVERED.equals(action)
|| NfcAdapter.ACTION_NDEF_DISCOVERED.equals(action)) {
Parcelable[] rawMsgs = intent.getParcelableArrayExtra(NfcAdapter.EXTRA_NDEF_MESSAGES);
NdefMessage[] msgs;
if (rawMsgs != null) {
msgs = new NdefMessage[rawMsgs.length];
for (int i = 0; i < rawMsgs.length; i++) {
msgs[i] = (NdefMessage) rawMsgs[i];
}
} else {
// Unknown tag type
//byte[] empty = new byte[0];
//byte[] id = intent.getByteArrayExtra(NfcAdapter.EXTRA_ID);
Tag tag = intent.getParcelableExtra(NfcAdapter.EXTRA_TAG);
showTagId(tag);
//byte[] payload = dumpTagData(tag).getBytes();
//NdefRecord record = new NdefRecord(NdefRecord.TNF_UNKNOWN, empty, id, payload);
//NdefMessage msg = new NdefMessage(new NdefRecord[] { record });
//msgs = new NdefMessage[] { msg };
}
// Setup the views
//buildTagViews(msgs);
}
}
示例15: onNewIntent
import android.nfc.Tag; //導入依賴的package包/類
@Override
protected void onNewIntent(Intent intent) {
super.onNewIntent(intent);
if (intent.hasExtra(NfcAdapter.EXTRA_TAG)) {
Toast.makeText(this, "NfcIntent!", Toast.LENGTH_SHORT).show();
Tag tag = intent.getParcelableExtra(NfcAdapter.EXTRA_TAG);
NdefMessage ndefMessage = createNdefMessage("My string content!");
writeNdefMessage(tag, ndefMessage);
}
}