当前位置: 首页>>代码示例>>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;未经允许,请勿转载。