Example usage for android.nfc Tag getTechList

List of usage examples for android.nfc Tag getTechList

Introduction

In this page you can find the example usage for android.nfc Tag getTechList.

Prototype

public String[] getTechList() 

Source Link

Document

Get the technologies available in this tag, as fully qualified class names.

Usage

From source file:jp.co.brilliantservice.android.writertdtext.HomeActivity.java

@Override
protected void onNewIntent(Intent intent) {
    super.onNewIntent(intent);

    String action = intent.getAction();
    if (TextUtils.isEmpty(action))
        return;// w  ww  .ja v  a 2 s . co m

    if (!action.equals(NfcAdapter.ACTION_TECH_DISCOVERED))
        return;

    // NdefMessage?
    String languageCode = "en";
    String text = String.format("Hello, World.(%s)", DATE_FORMAT.format(System.currentTimeMillis()));
    NdefMessage message = createTextMessage(text, languageCode);

    // ??????????
    Tag tag = (Tag) intent.getParcelableExtra(NfcAdapter.EXTRA_TAG);
    List<String> techList = Arrays.asList(tag.getTechList());
    if (techList.contains(Ndef.class.getName())) {
        Ndef ndef = Ndef.get(tag);
        writeNdefToNdefTag(ndef, message);

        Toast.makeText(getApplicationContext(), "wrote NDEF to NDEF tag", Toast.LENGTH_SHORT).show();
    } else if (techList.contains(NdefFormatable.class.getName())) {
        NdefFormatable ndef = NdefFormatable.get(tag);
        writeNdefToNdefFormatable(ndef, message);

        Toast.makeText(getApplicationContext(), "wrote NDEF to NDEFFormatable tag", Toast.LENGTH_SHORT).show();
    } else {
        Toast.makeText(getApplicationContext(), "NDEF Not Supported", Toast.LENGTH_SHORT).show();
    }
}

From source file:com.codebutler.farebot.activity.AddKeyActivity.java

@Override
protected void onNewIntent(Intent intent) {
    Tag tag = intent.getParcelableExtra("android.nfc.extra.TAG");
    mTagId = Utils.getHexString(tag.getId(), "");

    if (ArrayUtils.contains(tag.getTechList(), "android.nfc.tech.MifareClassic")) {
        mCardType = "MifareClassic";
        ((TextView) findViewById(R.id.card_type)).setText("MIFARE Classic");
        ((TextView) findViewById(R.id.card_id)).setText(mTagId);
        ((TextView) findViewById(R.id.key_data)).setText(Utils.getHexString(mKeyData, "").toUpperCase());

        findViewById(R.id.directions).setVisibility(View.GONE);
        findViewById(R.id.info).setVisibility(View.VISIBLE);
        findViewById(R.id.add).setVisibility(View.VISIBLE);

    } else {// w  w  w.  j  a v  a2s.c  o  m
        new AlertDialog.Builder(this).setMessage(R.string.card_keys_not_supported)
                .setPositiveButton(android.R.string.ok, null).show();
    }
}

From source file:jp.co.brilliantservice.android.writertduri.HomeActivity.java

@Override
protected void onNewIntent(Intent intent) {
    super.onNewIntent(intent);

    String action = intent.getAction();
    if (TextUtils.isEmpty(action))
        return;//from   w w  w .  j  a  va 2 s  . c o m

    if (!action.equals(NfcAdapter.ACTION_TECH_DISCOVERED))
        return;

    // NdefMessage?
    String uri = "http://www.brilliantservice.co.jp/";
    NdefMessage message = createUriMessage(uri);

    // ??????????
    Tag tag = (Tag) intent.getParcelableExtra(NfcAdapter.EXTRA_TAG);
    List<String> techList = Arrays.asList(tag.getTechList());
    if (techList.contains(Ndef.class.getName())) {
        Ndef ndef = Ndef.get(tag);
        writeNdefToNdefTag(ndef, message);

        Toast.makeText(getApplicationContext(), "wrote NDEF to NDEF tag", Toast.LENGTH_SHORT).show();
    } else if (techList.contains(NdefFormatable.class.getName())) {
        NdefFormatable ndef = NdefFormatable.get(tag);
        writeNdefToNdefFormatable(ndef, message);

        Toast.makeText(getApplicationContext(), "wrote NDEF to NDEFFormatable tag", Toast.LENGTH_SHORT).show();
    } else {
        Toast.makeText(getApplicationContext(), "NDEF Not Supported", Toast.LENGTH_SHORT).show();
    }
}

From source file:com.tananaev.passportreader.MainActivity.java

@Override
public void onNewIntent(Intent intent) {
    if (NfcAdapter.ACTION_TECH_DISCOVERED.equals(intent.getAction())) {
        Tag tag = intent.getExtras().getParcelable(NfcAdapter.EXTRA_TAG);
        if (Arrays.asList(tag.getTechList()).contains("android.nfc.tech.IsoDep")) {
            SharedPreferences preferences = PreferenceManager.getDefaultSharedPreferences(this);
            String passportNumber = preferences.getString(KEY_PASSPORT_NUMBER, null);
            String expirationDate = convertDate(preferences.getString(KEY_EXPIRATION_DATE, null));
            String birthDate = convertDate(preferences.getString(KEY_BIRTH_DATE, null));
            if (passportNumber != null && !passportNumber.isEmpty() && expirationDate != null
                    && !expirationDate.isEmpty() && birthDate != null && !birthDate.isEmpty()) {
                BACKeySpec bacKey = new BACKey(passportNumber, birthDate, expirationDate);
                new ReadTask(IsoDep.get(tag), bacKey).execute();
                mainLayout.setVisibility(View.GONE);
                loadingLayout.setVisibility(View.VISIBLE);
            } else {
                Snackbar.make(passportNumberView, R.string.error_input, Snackbar.LENGTH_SHORT).show();
            }//from w  w  w .j av  a2s. co m
        }
    }
}

From source file:de.syss.MifareClassicTool.Common.java

/**
 * Check if the tag and the device support the Mifare Classic technology.
 * @param tag The tag to check./*  w w w. ja  v  a 2  s  . c  o m*/
 * @param context The context of the package manager.
 * @return
 * <ul>
 * <li>0 - Device and tag support Mifare Classic.</li>
 * <li>-1 - Device does not support Mifare Classic.</li>
 * <li>-2 - Tag does not support Mifare Classic.</li>
 * <li>-3 - Error (tag or context is null).</li>
 * </ul>
 */
public static int checkMifareClassicSupport(Tag tag, Context context) {
    if (tag == null || context == null) {
        // Error.
        return -3;
    }

    if (Arrays.asList(tag.getTechList()).contains(MifareClassic.class.getName())) {
        // Device and tag support Mifare Classic.
        return 0;

        // This is no longer valid. There are some devices (e.g. LG's F60)
        // that have this system feature but no Mifare Classic support.
        // (The F60 has a Broadcom NFC controller.)
        /*
        } else if (context.getPackageManager().hasSystemFeature(
        "com.nxp.mifare")){
            // Tag does not support Mifare Classic.
            return -2;
        */

    } else {
        // Check if device does not support Mifare Classic.
        // For doing so, check if the ATQA + SAK of the tag indicate that
        // it's a Mifare Classic tag.
        // See: http://www.nxp.com/documents/application_note/AN10833.pdf
        // (Table 5 and 6)
        // 0x28 is for some emulated tags.
        NfcA nfca = NfcA.get(tag);
        byte[] atqa = nfca.getAtqa();
        if (atqa[1] == 0
                && (atqa[0] == 4 || atqa[0] == (byte) 0x44 || atqa[0] == 2 || atqa[0] == (byte) 0x42)) {
            // ATQA says it is most likely a Mifare Classic tag.
            byte sak = (byte) nfca.getSak();
            if (sak == 8 || sak == 9 || sak == (byte) 0x18 || sak == (byte) 0x88 || sak == (byte) 0x28) {
                // SAK says it is most likely a Mifare Classic tag.
                // --> Device does not support Mifare Classic.
                return -1;
            }
        }
        // Nope, it's not the device (most likely).
        // The tag does not support Mifare Classic.
        return -2;
    }
}

From source file:net.zjy.zxcardumper.Common.java

/**
 * Check if the tag and the device support the MIFARE Classic technology.
 * @param tag The tag to check.//from   w  ww  .jav a  2s  .  c o  m
 * @param context The context of the package manager.
 * @return
 * <ul>
 * <li>0 - Device and tag support MIFARE Classic.</li>
 * <li>-1 - Device does not support MIFARE Classic.</li>
 * <li>-2 - Tag does not support MIFARE Classic.</li>
 * <li>-3 - Error (tag or context is null).</li>
 * </ul>
 */
public static int checkMifareClassicSupport(Tag tag, Context context) {
    if (tag == null || context == null) {
        // Error.
        return -3;
    }

    if (Arrays.asList(tag.getTechList()).contains(MifareClassic.class.getName())) {
        // Device and tag support MIFARE Classic.
        return 0;

        // This is no longer valid. There are some devices (e.g. LG's F60)
        // that have this system feature but no MIFARE Classic support.
        // (The F60 has a Broadcom NFC controller.)
        /*
        } else if (context.getPackageManager().hasSystemFeature(
        "com.nxp.mifare")){
            // Tag does not support MIFARE Classic.
            return -2;
        */

    } else {
        // Check if device does not support MIFARE Classic.
        // For doing so, check if the ATQA + SAK of the tag indicate that
        // it's a MIFARE Classic tag.
        // See: http://www.nxp.com/documents/application_note/AN10833.pdf
        // (Table 5 and 6)
        // 0x28 is for some emulated tags.
        NfcA nfca = NfcA.get(tag);
        byte[] atqa = nfca.getAtqa();
        if (atqa[1] == 0
                && (atqa[0] == 4 || atqa[0] == (byte) 0x44 || atqa[0] == 2 || atqa[0] == (byte) 0x42)) {
            // ATQA says it is most likely a MIFARE Classic tag.
            byte sak = (byte) nfca.getSak();
            if (sak == 8 || sak == 9 || sak == (byte) 0x18 || sak == (byte) 0x88 || sak == (byte) 0x28) {
                // SAK says it is most likely a MIFARE Classic tag.
                // --> Device does not support MIFARE Classic.
                return -1;
            }
        }
        // Nope, it's not the device (most likely).
        // The tag does not support MIFARE Classic.
        return -2;
    }
}

From source file:st.alr.homA.ActivityQuickpublishNfc.java

@Override
protected void onNewIntent(Intent intent) {
    Log.v(this.toString(), "write mode: " + writeMode);
    if (NfcAdapter.ACTION_TAG_DISCOVERED.equals(intent.getAction()) && writeMode == true) {
        Tag mytag = intent.getParcelableExtra(NfcAdapter.EXTRA_TAG);
        Log.v(this.toString(), "Detected tag: " + mytag.toString());
        Log.v(this.toString(), "techlist:" + mytag.getTechList());

        ArrayList<Quickpublish> qps = adapter.getValues();
        if (qps.size() < 1) {
            publishProgress(getResources().getString(R.string.nfcWriteDialogTagNoContent), false);
            return;
        }/*from www  .j  a  v a 2 s.  c o m*/

        if (write(Quickpublish.toJsonString(qps), mytag)) {
            Log.v(this.toString(), "Write ok");
            publishProgress(getResources().getString(R.string.nfcWriteDialogTagSuccess), true);

        } else {
            Log.e(this.toString(), "Write fail");
        }
    }
}

From source file:foundme.uniroma2.it.professore.HomeActivity.java

private void handleIntent(Intent intent) {
    String action = intent.getAction();

    if (NfcAdapter.ACTION_NDEF_DISCOVERED.equals(action)) {

        String type = intent.getType();
        if (Variables_it.MIME_TEXT_PLAIN.equals(type)) {

            Tag tag = intent.getParcelableExtra(NfcAdapter.EXTRA_TAG);
            new NdefReaderTask().execute(tag);

        }//from   www  .j  av a 2s  .  c  om
    } else if (NfcAdapter.ACTION_TECH_DISCOVERED.equals(action)) {

        // In questo caso usermo la Tech Discovered Intent
        Tag tag = intent.getParcelableExtra(NfcAdapter.EXTRA_TAG);
        String[] techList = tag.getTechList();
        String searchedTech = Ndef.class.getName();

        for (String tech : techList) {
            if (searchedTech.equals(tech)) {
                new NdefReaderTask().execute(tag);
                break;
            }
        }
    }
}

From source file:se.anyro.nfc_reader.TagViewer.java

private String dumpTagData(Parcelable p) {
    StringBuilder sb = new StringBuilder();
    Tag tag = (Tag) p;
    byte[] id = tag.getId();
    sb.append("Tag ID (hex): ").append(getHex(id)).append("\n");
    sb.append("Tag ID (dec): ").append(getDec(id)).append("\n");
    sb.append("ID (reversed): ").append(getReversed(id)).append("\n");

    String prefix = "android.nfc.tech.";
    sb.append("Technologies: ");
    for (String tech : tag.getTechList()) {
        sb.append(tech.substring(prefix.length()));
        sb.append(", ");
    }/*from  w  w w . j ava  2s  .co  m*/
    sb.delete(sb.length() - 2, sb.length());
    for (String tech : tag.getTechList()) {
        if (tech.equals(MifareClassic.class.getName())) {
            sb.append('\n');
            MifareClassic mifareTag = MifareClassic.get(tag);
            String type = "Unknown";
            switch (mifareTag.getType()) {
            case MifareClassic.TYPE_CLASSIC:
                type = "Classic";
                break;
            case MifareClassic.TYPE_PLUS:
                type = "Plus";
                break;
            case MifareClassic.TYPE_PRO:
                type = "Pro";
                break;
            }
            sb.append("Mifare Classic type: ");
            sb.append(type);
            sb.append('\n');

            sb.append("Mifare size: ");
            sb.append(mifareTag.getSize() + " bytes");
            sb.append('\n');

            sb.append("Mifare sectors: ");
            sb.append(mifareTag.getSectorCount());
            sb.append('\n');

            sb.append("Mifare blocks: ");
            sb.append(mifareTag.getBlockCount());
        }

        if (tech.equals(MifareUltralight.class.getName())) {
            sb.append('\n');
            MifareUltralight mifareUlTag = MifareUltralight.get(tag);
            String type = "Unknown";
            switch (mifareUlTag.getType()) {
            case MifareUltralight.TYPE_ULTRALIGHT:
                type = "Ultralight";
                break;
            case MifareUltralight.TYPE_ULTRALIGHT_C:
                type = "Ultralight C";
                break;
            }
            sb.append("Mifare Ultralight type: ");
            sb.append(type);
        }
    }

    return sb.toString();
}