Example usage for android.nfc NfcAdapter ACTION_NDEF_DISCOVERED

List of usage examples for android.nfc NfcAdapter ACTION_NDEF_DISCOVERED

Introduction

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

Prototype

String ACTION_NDEF_DISCOVERED

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

Click Source Link

Document

Intent to start an activity when a tag with NDEF payload is discovered.

Usage

From source file:org.ndeftools.NfcDetectorActivity.java

/**
 * /*from w  w  w.j  a  v  a 2 s . c o  m*/
 * Initialize Nfc fields
 * 
 */

protected void initializeNfc() {
    nfcAdapter = NfcAdapter.getDefaultAdapter(this);
    nfcPendingIntent = PendingIntent.getActivity(this, 0,
            new Intent(this, this.getClass()).addFlags(Intent.FLAG_ACTIVITY_SINGLE_TOP), 0);

    IntentFilter tagDetected = new IntentFilter(NfcAdapter.ACTION_TAG_DISCOVERED);
    IntentFilter ndefDetected = new IntentFilter(NfcAdapter.ACTION_NDEF_DISCOVERED);
    IntentFilter techDetected = new IntentFilter(NfcAdapter.ACTION_TECH_DISCOVERED);
    writeTagFilters = new IntentFilter[] { ndefDetected, tagDetected, techDetected };
}

From source file:net.networksaremadeofstring.rhybudd.PushSettingsFragment.java

@Override
public void onResume() {
    super.onResume();

    try {//w w w  .  j  av a  2  s . c  o  m
        if (NfcAdapter.ACTION_NDEF_DISCOVERED.equals(getActivity().getIntent().getAction())) {
            processIntent(getActivity().getIntent());
        }
    } catch (Exception e) {
        BugSenseHandler.sendExceptionMessage("PushSettingsFragment", "onResume", e);
    }
}

From source file:de.gadc.moneybeam.ReceiveRequestActivity.java

@Override
public void onResume() {
    super.onResume();
    if (NfcAdapter.ACTION_NDEF_DISCOVERED.equals(getIntent().getAction())) {
        processIntent(getIntent());//from  w  w  w. j a  v a  2 s.  c om
    }
}

From source file:com.bonsai.wallet32.PairWalletActivity.java

@Override
protected void onCreate(Bundle savedInstanceState) {
    mRes = getApplicationContext().getResources();
    mPrefs = PreferenceManager.getDefaultSharedPreferences(this);
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_pair_wallet);

    // Set the state of the reduce false positives checkbox.
    boolean reduceFalsePositives = mPrefs.getBoolean("pref_reduceBloomFalsePositives", false);
    CheckBox chkbx = (CheckBox) findViewById(R.id.reduce_false_positives);
    chkbx.setChecked(reduceFalsePositives);
    chkbx.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
        @Override// w  w  w. j a v a  2 s . c  o m
        public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
            SharedPreferences.Editor editor = mPrefs.edit();
            editor.putBoolean("pref_reduceBloomFalsePositives", isChecked);
            editor.commit();
        }
    });

    // Hide the reduce bloom false positives if experimental off.
    Boolean isExperimental = mPrefs.getBoolean(SettingsActivity.KEY_EXPERIMENTAL, false);
    if (!isExperimental) {
        findViewById(R.id.reduce_false_positives).setVisibility(View.GONE);
        findViewById(R.id.reduce_space).setVisibility(View.GONE);
    }

    if (savedInstanceState == null) {
        final Intent intent = this.getIntent();
        final String action = intent.getAction();
        final String mimeType = intent.getType();

        if ((NfcAdapter.ACTION_NDEF_DISCOVERED.equals(action))
                && Nfc.MIMETYPE_WALLET32PAIRING.equals(mimeType)) {
            final NdefMessage ndefMessage = (NdefMessage) intent
                    .getParcelableArrayExtra(NfcAdapter.EXTRA_NDEF_MESSAGES)[0];
            final byte[] ndefMessagePayload = Nfc.extractMimePayload(Nfc.MIMETYPE_WALLET32PAIRING, ndefMessage);
            JSONObject codeObj;

            try {
                String msg = new String(ndefMessagePayload, "UTF-8");
                codeObj = new JSONObject(msg);
            } catch (Exception ex) {
                String msg = "trouble deserializing pairing code: " + ex.toString() + " : "
                        + ndefMessagePayload.toString();
                mLogger.error(msg);
                Toast.makeText(this, msg, Toast.LENGTH_LONG).show();
                return;
            }

            // Setup the wallet in a background task.
            new PairWalletTask().execute(codeObj);
        }
    }
}

From source file:edu.stanford.mobisocial.dungbeetle.HandleNfcContact.java

public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    Intent intent = getIntent();/*from w w w .j  a  v a 2s  .c  o m*/
    final Uri uri = intent.getData();

    setContentView(R.layout.handle_give);
    Button saveButton = (Button) findViewById(R.id.save_contact_button);
    Button cancelButton = (Button) findViewById(R.id.cancel_button);
    Button mutualFriendsButton = (Button) findViewById(R.id.mutual_friends_button);
    mutualFriendsButton.setVisibility(View.GONE);

    if (uri != null && (uri.getScheme().equals(HomeActivity.SHARE_SCHEME)
            || uri.getSchemeSpecificPart().startsWith(FriendRequest.PREFIX_JOIN))) {

        mEmail = uri.getQueryParameter("email");

        mName = uri.getQueryParameter("name");
        if (mName == null) {
            mName = mEmail;

        }

        TextView nameView = (TextView) findViewById(R.id.name_text);
        nameView.setText("Would you like to be friends with " + mName + "?");

        final long cid = FriendRequest.acceptFriendRequest(HandleNfcContact.this, uri, false);
        saveButton.setOnClickListener(new OnClickListener() {
            public void onClick(View v) {
                DBHelper helper = DBHelper.getGlobal(HandleNfcContact.this);
                IdentityProvider ident = new DBIdentityProvider(helper);

                try {
                    JSONObject profile = new JSONObject(ident.userProfile());
                    byte[] data = FastBase64.decode(profile.getString("picture"));

                    Helpers.updatePicture(HandleNfcContact.this, data);
                } catch (Exception e) {
                }

                // If asymmetric friend request, send public key.
                if (!NfcAdapter.ACTION_NDEF_DISCOVERED.equals(getIntent().getAction())) {
                    FriendRequest.sendFriendRequest(HandleNfcContact.this, cid, uri.getQueryParameter("cap"));
                }

                Toast.makeText(HandleNfcContact.this, "Added " + mName + " as a friend.", Toast.LENGTH_SHORT)
                        .show();
                finish();
            }
        });

        cancelButton.setOnClickListener(new OnClickListener() {
            public void onClick(View v) {
                Helpers.deleteContact(HandleNfcContact.this, cid);
                finish();
            }
        });

        ImageView portraitView = (ImageView) findViewById(R.id.image);
        if (uri != null) {
            /*
                ((App)getApplication()).contactImages.lazyLoadImage(
            mEmail.hashCode(),
            Gravatar.gravatarUri(mEmail, 100), 
            portraitView);
            */

            //((App)getApplication()).contactImages.lazyLoadImage(mPicture.hashCode(), mPicture, portraitView);
        }
    } else {
        saveButton.setEnabled(false);
        cancelButton.setOnClickListener(new OnClickListener() {
            public void onClick(View v) {
                finish();
            }
        });
        Toast.makeText(this, "Failed to receive contact.", Toast.LENGTH_SHORT).show();
        Log.d(TAG, "Failed to handle " + uri);
    }
}

From source file:org.sufficientlysecure.keychain.ui.CreateKeyActivity.java

@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    // React on NDEF_DISCOVERED from Manifest
    // NOTE: ACTION_NDEF_DISCOVERED and not ACTION_TAG_DISCOVERED like in BaseNfcActivity
    if (NfcAdapter.ACTION_NDEF_DISCOVERED.equals(getIntent().getAction())) {

        mNfcTagDispatcher.interceptIntent(getIntent());

        setTitle(R.string.title_manage_my_keys);

        // done/*from  w  w w . jav  a 2  s  . c o m*/
        return;
    }

    // Check whether we're recreating a previously destroyed instance
    if (savedInstanceState != null) {
        // Restore value of members from saved state
        mName = savedInstanceState.getString(EXTRA_NAME);
        mEmail = savedInstanceState.getString(EXTRA_EMAIL);
        mAdditionalEmails = savedInstanceState.getStringArrayList(EXTRA_ADDITIONAL_EMAILS);
        mPassphrase = savedInstanceState.getParcelable(EXTRA_PASSPHRASE);
        mFirstTime = savedInstanceState.getBoolean(EXTRA_FIRST_TIME);
        mCreateSecurityToken = savedInstanceState.getBoolean(EXTRA_CREATE_SECURITY_TOKEN);
        mSecurityTokenAid = savedInstanceState.getByteArray(EXTRA_SECURITY_TOKEN_AID);
        mSecurityTokenPin = savedInstanceState.getParcelable(EXTRA_SECURITY_TOKEN_PIN);
        mSecurityTokenAdminPin = savedInstanceState.getParcelable(EXTRA_SECURITY_TOKEN_ADMIN_PIN);

        mCurrentFragment = getSupportFragmentManager().findFragmentByTag(FRAGMENT_TAG);
    } else {

        Intent intent = getIntent();
        // Initialize members with default values for a new instance
        mName = intent.getStringExtra(EXTRA_NAME);
        mEmail = intent.getStringExtra(EXTRA_EMAIL);
        mFirstTime = intent.getBooleanExtra(EXTRA_FIRST_TIME, false);
        mCreateSecurityToken = intent.getBooleanExtra(EXTRA_CREATE_SECURITY_TOKEN, false);

        if (intent.hasExtra(EXTRA_SECURITY_FINGERPRINTS)) {
            byte[] nfcFingerprints = intent.getByteArrayExtra(EXTRA_SECURITY_FINGERPRINTS);
            String nfcUserId = intent.getStringExtra(EXTRA_SECURITY_TOKEN_USER_ID);
            byte[] nfcAid = intent.getByteArrayExtra(EXTRA_SECURITY_TOKEN_AID);

            if (containsKeys(nfcFingerprints)) {
                Fragment frag = CreateSecurityTokenImportResetFragment.newInstance(nfcFingerprints, nfcAid,
                        nfcUserId);
                loadFragment(frag, FragAction.START);

                setTitle(R.string.title_import_keys);
            } else {
                Fragment frag = CreateSecurityTokenBlankFragment.newInstance(nfcAid);
                loadFragment(frag, FragAction.START);
                setTitle(R.string.title_manage_my_keys);
            }

            // done
            return;
        }

        // normal key creation
        CreateKeyStartFragment frag = CreateKeyStartFragment.newInstance();
        loadFragment(frag, FragAction.START);
    }

    if (mFirstTime) {
        setTitle(R.string.app_name);
        mToolbar.setNavigationIcon(null);
        mToolbar.setNavigationOnClickListener(null);
    } else {
        setTitle(R.string.title_manage_my_keys);
    }
}

From source file:mai.whack.StickyNotesActivity.java

/** Called when the activity is first created. */
@Override//from  w w  w.j  av  a  2  s  .co m
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    mNfcAdapter = NfcAdapter.getDefaultAdapter(this);

    setContentView(R.layout.main);
    findViewById(R.id.write_tag).setOnClickListener(mTagWriter);

    // Handle all of our received NFC intents in this activity.
    mNfcPendingIntent = PendingIntent.getActivity(this, 0,
            new Intent(this, getClass()).addFlags(Intent.FLAG_ACTIVITY_SINGLE_TOP), 0);

    // Intent filters for reading a note from a tag or exchanging over p2p.
    IntentFilter ndefDetected = new IntentFilter(NfcAdapter.ACTION_NDEF_DISCOVERED);
    try {
        ndefDetected.addDataType("text/plain");
    } catch (MalformedMimeTypeException e) {
    }
    mNdefExchangeFilters = new IntentFilter[] { ndefDetected };

    // Intent filters for writing to a tag
    IntentFilter tagDetected = new IntentFilter(NfcAdapter.ACTION_TAG_DISCOVERED);
    mWriteTagFilters = new IntentFilter[] { tagDetected };
}

From source file:com.battlelancer.seriesguide.ui.AddActivity.java

@Override
public void onResume() {
    super.onResume();
    if (AndroidUtils.isICSOrHigher()) {
        // Check to see that the Activity started due to an Android Beam
        if (NfcAdapter.ACTION_NDEF_DISCOVERED.equals(getIntent().getAction())) {
            processIntent(getIntent());//  ww  w. j a v  a2  s .  co m
        }
    }
}

From source file:org.sufficientlysecure.keychain.ui.ImportKeysProxyActivity.java

protected void handleActions(Intent intent) {
    String action = intent.getAction();
    Uri dataUri = intent.getData();//  w w  w. j a v  a 2  s. c  om
    String scheme = intent.getScheme();

    if (scheme != null && scheme.toLowerCase(Locale.ENGLISH).equals(Constants.FINGERPRINT_SCHEME)) {
        // Scanning a fingerprint directly with Barcode Scanner, thus we already have scanned

        processScannedContent(dataUri);
    } else if (ACTION_SCAN_WITH_RESULT.equals(action) || ACTION_SCAN_IMPORT.equals(action)
            || ACTION_QR_CODE_API.equals(action)) {
        new IntentIntegrator(this).setCaptureActivity(QrCodeCaptureActivity.class).initiateScan();
    } else if (NfcAdapter.ACTION_NDEF_DISCOVERED.equals(getIntent().getAction())) {
        // Check to see if the Activity started due to an Android Beam
        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN) {
            handleActionNdefDiscovered(getIntent());
        } else {
            Log.e(Constants.TAG, "Android Beam not supported by Android < 4.1");
            finish();
        }
    } else {
        Log.e(Constants.TAG, "No valid scheme or action given!");
        finish();
    }
}

From source file:mai.whack.StickyNotesActivity.java

@Override
protected void onResume() {
    super.onResume();
    // Sticky notes received from Android
    if (!mResumed && NfcAdapter.ACTION_NDEF_DISCOVERED.equals(getIntent().getAction())) {
        onDataRead(getIntent());//from  w w  w .  j a v  a  2  s.  c  o m
        mResumed = true;
    }
    enableNdefExchangeMode();
}