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


Java Tag類代碼示例

本文整理匯總了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);

    }
 
開發者ID:petersobolev,項目名稱:nfc-react-native-simple,代碼行數:17,代碼來源:NfcReactNativeSimpleModule.java

示例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);
    }
}
 
開發者ID:mDL-ILP,項目名稱:mDL-ILP,代碼行數:22,代碼來源:NFCConnection.java

示例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());
    }
}
 
開發者ID:ThomasDelaney,項目名稱:TapIn,代碼行數:21,代碼來源:add3.java

示例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);
}
 
開發者ID:jopenbox,項目名稱:android-nfc,代碼行數:18,代碼來源:WriteMUActivity.java

示例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();
}
 
開發者ID:jopenbox,項目名稱:android-nfc,代碼行數:20,代碼來源:ReadMUActivity.java

示例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();
    }
}
 
開發者ID:jopenbox,項目名稱:android-nfc,代碼行數:11,代碼來源:WriteUriActivity.java

示例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;
}
 
開發者ID:jopenbox,項目名稱:android-nfc,代碼行數:27,代碼來源:WriteUriActivity.java

示例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);
}
 
開發者ID:theGreatWhiteShark,項目名稱:mensacard-hack,代碼行數:8,代碼來源:NfcPlugin.java

示例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;
		}
	}
}
 
開發者ID:RowanACM,項目名稱:RFID-Attendance,代碼行數:22,代碼來源:NfcManager.java

示例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);
        }
    }
}
 
開發者ID:AinaWireless,項目名稱:PairingExample,代碼行數:22,代碼來源:MainActivity.java

示例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);
    }
}
 
開發者ID:rainhard,項目名稱:wNFCard,代碼行數:28,代碼來源:NewCardActivity.java

示例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);
    }
}
 
開發者ID:tekesan,項目名稱:TraiNFCUI,代碼行數:14,代碼來源:Tap.java


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