Example usage for android.nfc NfcAdapter ACTION_TECH_DISCOVERED

List of usage examples for android.nfc NfcAdapter ACTION_TECH_DISCOVERED

Introduction

In this page you can find the example usage for android.nfc NfcAdapter ACTION_TECH_DISCOVERED.

Prototype

String ACTION_TECH_DISCOVERED

To view the source code for android.nfc NfcAdapter ACTION_TECH_DISCOVERED.

Click Source Link

Document

Intent to start an activity when a tag is discovered and activities are registered for the specific technologies on the tag.

Usage

From source file:de.yazo_games.mensaguthaben.MainActivity.java

@Override
public void onNewIntent(Intent intent) {
    Log.i(TAG, "Foreground dispatch");
    if (NfcAdapter.ACTION_TECH_DISCOVERED.equals(intent.getAction())) {
        Log.i(TAG, "Discovered tag with intent: " + intent);
        Tag tag = intent.getParcelableExtra(NfcAdapter.EXTRA_TAG);

        try {/*from  ww w  .j av  a2s .  co m*/
            ValueData val = Readers.getInstance().readTag(tag);
            Log.w(TAG, "Setting read data");
            valueFragment.setValueData(val);
            hasNewData = true;

        } catch (DesfireException e) {
            Toast.makeText(this, R.string.communication_fail, Toast.LENGTH_SHORT).show();
        }
    } else if (getIntent().getAction().equals(ACTION_FULLSCREEN)) {
        ValueData valueData = (ValueData) getIntent().getSerializableExtra(EXTRA_VALUE);
        valueFragment.setValueData(valueData);

    }
}

From source file:nl.hnogames.domoticz.NFCSettingsActivity.java

protected void onResume() {
    super.onResume();

    try {//from   ww  w. j  a v a2 s .c om
        // creating pending intent:
        PendingIntent mPendingIntent = PendingIntent.getActivity(this, 0,
                new Intent(this, getClass()).addFlags(Intent.FLAG_ACTIVITY_SINGLE_TOP), 0);

        // creating intent receiver for NFC events:
        IntentFilter filter = new IntentFilter();
        filter.addAction(NfcAdapter.ACTION_TAG_DISCOVERED);
        filter.addAction(NfcAdapter.ACTION_NDEF_DISCOVERED);
        filter.addAction(NfcAdapter.ACTION_TECH_DISCOVERED);

        // enabling foreground dispatch for getting intent from NFC event:
        if (mNfcAdapter == null) {
            mNfcAdapter = NfcAdapter.getDefaultAdapter(this);

            if (mNfcAdapter != null) {
                UsefulBits.showSnackbar(this, coordinatorLayout, R.string.nfc_register, Snackbar.LENGTH_SHORT);
            } else {
                UsefulBits.showSnackbar(this, coordinatorLayout, R.string.nfc_not_supported,
                        Snackbar.LENGTH_SHORT);
            }
        }
        if (mNfcAdapter != null)
            mNfcAdapter.enableForegroundDispatch(this, mPendingIntent, new IntentFilter[] { filter },
                    this.techList);
    } catch (Exception ex) {
        Log.e(this.getClass().getSimpleName(), ex.getMessage());
    }
}

From source file:org.adictolinux.mfcclone.MainActivity.java

@Override
public void onNewIntent(Intent intent) {
    String action = intent.getAction();

    if (scan_fragment != null && NfcAdapter.ACTION_TECH_DISCOVERED.equals(action)) {

        Tag tag = (Tag) intent.getExtras().getParcelable(NfcAdapter.EXTRA_TAG);

        switch (scan_fragment_type) {
        case 0:/*from  w  w w . j  ava  2s  .  c o  m*/
            ((ForceKeysFragment) scan_fragment).tagFound(tag);
            break;
        case 1:
            ((ImportTagFragment) scan_fragment).tagFound(tag);
            break;
        case 2:
            ((SaveTagDataFragment) scan_fragment).tagFound(tag);
            break;
        case 5:
            ((ResetTagFragment) scan_fragment).tagFound(tag);
            break;
        }
    }
}

From source file:com.support.android.designlibdemo.EditContactActivity.java

@Override
public void onNewIntent(Intent intent) {
    Log.e("Search Query: ", "onNewIntent Query: ");
    int typeCheck = Common.treatAsNewTag(intent, this);
    if (typeCheck == -1 || typeCheck == -2) {
        // Device or tag does not support Mifare Classic.
        // Run the only thing that is possible: The tag info tool.
        Intent i = new Intent(this, TagInfoTool.class);
        startActivity(i);//from   www  .  j ava 2  s  .  c  o  m
    } else {
        if (typeCheck != -4) {
            if (cheeseName.compareTo("Editer") == 0) {
                reader = Common.checkForTagAndCreateReader(this);
                readTag(typeCheck);
            }
            // reader = Common.checkForTagAndCreateReader(this);
        }
    }
    if (NfcAdapter.ACTION_TECH_DISCOVERED.equals(intent.getAction())) {
        //updateTagInfo(Common.getTag());
    }
}

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

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;//from   w  w w .  j  ava2 s .com
        if (rawMsgs != null) {
            msgs = new NdefMessage[rawMsgs.length];
            for (int i = 0; i < rawMsgs.length; i++) {
                msgs[i] = (NdefMessage) rawMsgs[i];

                // magic happens here
                processReadTag((NdefMessage) rawMsgs[i]);
            }

        } else {
            // Unknown tag type
            byte[] empty = new byte[0];
            byte[] id = intent.getByteArrayExtra(NfcAdapter.EXTRA_ID);
            Parcelable tag = intent.getParcelableExtra(NfcAdapter.EXTRA_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);
    }
}

From source file:io.atrac613.AbstractNfcTagFragment.java

@Override
public void onResume() {
    Log.d(TAG, "*** AbstractNfcFeliCaTagFragment go Resume");

    //foregrandDispathch
    Activity a = this.getActivity();
    IntentFilter ndef = new IntentFilter(NfcAdapter.ACTION_NDEF_DISCOVERED);
    IntentFilter tag = new IntentFilter(NfcAdapter.ACTION_TAG_DISCOVERED);
    IntentFilter tech = new IntentFilter(NfcAdapter.ACTION_TECH_DISCOVERED);
    try {/*from   w w  w  .  j av  a 2s . c om*/
        ndef.addDataType("*/*");
    } catch (MalformedMimeTypeException e) {
        throw new RuntimeException("fail", e);
    }
    IntentFilter[] filters = new IntentFilter[] { ndef, tag, tech };

    PendingIntent pendingIntent = PendingIntent.getActivity(a, 0,
            new Intent(a, a.getClass()).addFlags(Intent.FLAG_ACTIVITY_SINGLE_TOP), 0);
    NfcAdapter adapter = NfcAdapter.getDefaultAdapter(this.getActivity());

    adapter.enableForegroundDispatch(this.getActivity(), pendingIntent, filters, registerTechList(mTechList));

    super.onResume();
}

From source file:com.securekey.sdk.sample.ReadCardActivity.java

private void enableForegroundDispatch() {
    Log.i("SDKSample", "enable foreground dispatch");
    if (NfcAdapter.getDefaultAdapter(this) != null) {
        try {//ww  w .ja v  a  2s. c  o  m
            NfcAdapter.getDefaultAdapter(this).enableForegroundDispatch(this,
                    PendingIntent.getActivity(this, 0,
                            new Intent(this, this.getClass()).addFlags(Intent.FLAG_ACTIVITY_SINGLE_TOP), 0),
                    new IntentFilter[] { new IntentFilter(NfcAdapter.ACTION_TECH_DISCOVERED) }, new String[][] {
                            new String[] { NfcA.class.getName() }, new String[] { NfcB.class.getName() } });
        } catch (Exception e) {
            Log.i("SDKSample", "enableForegroundDispatch failed");
        }
    }
}

From source file:io.atrac613.AbstractNfcTagFragment.java

/**
 * ???/*from  w w  w. j ava  2 s .c om*/
 * @param intent ?????????
 */
public void onNewIntent(Intent intent) {
    String action = intent.getAction();
    Log.d(TAG, "incomming intent action = " + action);

    //TECHDISCOVERED
    if (NfcAdapter.ACTION_TECH_DISCOVERED.equals(action) || NfcAdapter.ACTION_NDEF_DISCOVERED.equals(action)
            || NfcAdapter.ACTION_TAG_DISCOVERED.equals(action)) {
        mNfcTag = intent.getParcelableExtra(NfcAdapter.EXTRA_TAG);
        if (mNfcTag != null) {
            String[] tagTechs = mNfcTag.getTechList();
            for (String[] filterTechs : mTechList) {
                if (ArrayUtil.containArray(tagTechs, filterTechs)) {
                    Log.d(TAG, "** nfcTag = " + mNfcTag.toString());
                    for (INfcTagListener listener : mListnerList) {
                        //?
                        listener.onTagDiscovered(intent, mNfcTag, this);
                    }
                }
            }
        }
    }
}

From source file:org.ndeftools.NfcDetectorActivity.java

/**
 * /* w w w  .j a  va2  s  . c  o  m*/
 * Process the current intent, looking for NFC-related actions
 * 
 */

public void processIntent() {
    Intent intent = getIntent();
    // Check to see that the Activity started due to an Android Beam
    if (NfcAdapter.ACTION_NDEF_DISCOVERED.equals(intent.getAction())) {
        Log.d(TAG, "Process NDEF discovered action");

        nfcIntentDetected(intent, NfcAdapter.ACTION_NDEF_DISCOVERED);
    } else if (NfcAdapter.ACTION_TAG_DISCOVERED.equals(intent.getAction())) {
        Log.d(TAG, "Process APP_TAG discovered action");

        nfcIntentDetected(intent, NfcAdapter.ACTION_TAG_DISCOVERED);
    } else if (NfcAdapter.ACTION_TECH_DISCOVERED.equals(intent.getAction())) {
        Log.d(TAG, "Process TECH discovered action");

        nfcIntentDetected(intent, NfcAdapter.ACTION_TECH_DISCOVERED);
    } else {
        Log.d(TAG, "Ignore action " + intent.getAction());
    }
}

From source file:net.tjohns.badgescanner.ScanActivity.java

private void scanBadge() {
    Vibrator vibrator = (Vibrator) getSystemService(Context.VIBRATOR_SERVICE);
    vibrator.vibrate(VIBRATION_DURATION);

    Intent intent = getIntent();/*from w  ww .  j  av a 2  s. c om*/

    if (NfcAdapter.ACTION_TECH_DISCOVERED.equals(getIntent().getAction())) {
        Tag rawTag = intent.getParcelableExtra(NfcAdapter.EXTRA_TAG);
        MifareClassic tag = MifareClassic.get(rawTag);
        try {
            // Read from badge
            NfcConnection tagConnection = new NfcConnection(tag, MifareClassic.KEY_DEFAULT);
            mBadge = new Badge();
            mBadge.readFromTag(tagConnection);
            tagConnection.close();
        } catch (TagLostException e) {
            // TODO(trevorjohns): Convert to dialog
            Toast.makeText(this, "Tag lost", Toast.LENGTH_LONG);
            finish();
        } catch (IOException e) {
            // TODO(trevorjohns): Convert to dialog
            Toast.makeText(this, "IOExcpetion detected", Toast.LENGTH_LONG);
            e.printStackTrace();
            finish();
        }
    }
}