Search in sources :

Example 1 with Tag

use of android.nfc.Tag in project nfcspy by sinpolib.

the class NfcManager method setReaderMode.

@SuppressLint("NewApi")
private void setReaderMode(boolean enable, int delay) {
    if (nfcAdapter == null || !hasHCE())
        return;
    if (!enable) {
        nfcAdapter.disableReaderMode(activity);
        return;
    }
    Bundle opts = new Bundle();
    opts.putInt(NfcAdapter.EXTRA_READER_PRESENCE_CHECK_DELAY, 5000);
    int flags = NfcAdapter.FLAG_READER_SKIP_NDEF_CHECK;
    flags |= NfcAdapter.FLAG_READER_NFC_A;
    // For the 'READ BINARY' problem of Braodcom's NFC stack.
    // Only works on Android 4.4+
    nfcAdapter.enableReaderMode(activity, new ReaderCallback() {

        @Override
        public void onTagDiscovered(Tag tag) {
            Intent i = new Intent().putExtra(EXTRA_TAG, tag);
            tagListener.onNewTagIntent(i);
        }
    }, flags, opts);
}
Also used : ReaderCallback(android.nfc.NfcAdapter.ReaderCallback) Bundle(android.os.Bundle) Intent(android.content.Intent) PendingIntent(android.app.PendingIntent) Tag(android.nfc.Tag) SuppressLint(android.annotation.SuppressLint) SuppressLint(android.annotation.SuppressLint)

Example 2 with Tag

use of android.nfc.Tag in project cw-advandroid by commonsguy.

the class URLTagger method onNewIntent.

@Override
protected void onNewIntent(Intent intent) {
    if (inWriteMode && NfcAdapter.ACTION_TAG_DISCOVERED.equals(intent.getAction())) {
        Tag tag = intent.getParcelableExtra(NfcAdapter.EXTRA_TAG);
        byte[] url = buildUrlBytes(intent.getStringExtra(Intent.EXTRA_TEXT));
        NdefRecord record = new NdefRecord(NdefRecord.TNF_WELL_KNOWN, NdefRecord.RTD_URI, new byte[] {}, url);
        NdefMessage msg = new NdefMessage(new NdefRecord[] { record });
        new WriteTask(this, msg, tag).execute();
    }
}
Also used : NdefRecord(android.nfc.NdefRecord) NdefMessage(android.nfc.NdefMessage) Tag(android.nfc.Tag)

Example 3 with Tag

use of android.nfc.Tag in project cw-omnibus by commonsguy.

the class MainActivity method writeToTag.

void writeToTag(Intent i) {
    Tag tag = i.getParcelableExtra(NfcAdapter.EXTRA_TAG);
    NdefMessage msg = new NdefMessage(new NdefRecord[] { buildNdefRecord() });
    new WriteTagTask(this, msg, tag).execute();
}
Also used : NdefMessage(android.nfc.NdefMessage) Tag(android.nfc.Tag)

Example 4 with Tag

use of android.nfc.Tag in project cw-omnibus by commonsguy.

the class URLTagger method onNewIntent.

@Override
protected void onNewIntent(Intent intent) {
    if (inWriteMode && NfcAdapter.ACTION_TAG_DISCOVERED.equals(intent.getAction())) {
        Tag tag = intent.getParcelableExtra(NfcAdapter.EXTRA_TAG);
        byte[] url = buildUrlBytes(getIntent().getStringExtra(Intent.EXTRA_TEXT));
        NdefRecord record = new NdefRecord(NdefRecord.TNF_WELL_KNOWN, NdefRecord.RTD_URI, new byte[] {}, url);
        NdefMessage msg = new NdefMessage(new NdefRecord[] { record });
        new WriteTask(this, msg, tag).execute();
    }
}
Also used : NdefRecord(android.nfc.NdefRecord) NdefMessage(android.nfc.NdefMessage) Tag(android.nfc.Tag)

Example 5 with Tag

use of android.nfc.Tag in project Resurrection_packages_apps_Settings by ResurrectionRemix.

the class WriteWifiConfigToNfcDialog method onClick.

@Override
public void onClick(View v) {
    mWakeLock.acquire();
    String password = mPasswordView.getText().toString();
    String wpsNfcConfigurationToken = mWifiManager.getWpsNfcConfigurationToken(mNetworkId);
    String passwordHex = byteArrayToHexString(password.getBytes());
    String passwordLength = password.length() >= HEX_RADIX ? Integer.toString(password.length(), HEX_RADIX) : "0" + Character.forDigit(password.length(), HEX_RADIX);
    passwordHex = String.format(PASSWORD_FORMAT, passwordLength, passwordHex).toUpperCase();
    if (wpsNfcConfigurationToken.contains(passwordHex)) {
        mWpsNfcConfigurationToken = wpsNfcConfigurationToken;
        Activity activity = getOwnerActivity();
        NfcAdapter nfcAdapter = NfcAdapter.getDefaultAdapter(activity);
        nfcAdapter.enableReaderMode(activity, new NfcAdapter.ReaderCallback() {

            @Override
            public void onTagDiscovered(Tag tag) {
                handleWriteNfcEvent(tag);
            }
        }, NfcAdapter.FLAG_READER_NFC_A | NfcAdapter.FLAG_READER_NFC_B | NfcAdapter.FLAG_READER_NFC_BARCODE | NfcAdapter.FLAG_READER_NFC_F | NfcAdapter.FLAG_READER_NFC_V, null);
        mPasswordView.setVisibility(View.GONE);
        mPasswordCheckBox.setVisibility(View.GONE);
        mSubmitButton.setVisibility(View.GONE);
        InputMethodManager imm = (InputMethodManager) getOwnerActivity().getSystemService(Context.INPUT_METHOD_SERVICE);
        imm.hideSoftInputFromWindow(mPasswordView.getWindowToken(), 0);
        mLabelView.setText(R.string.status_awaiting_tap);
        mView.findViewById(R.id.password_layout).setTextAlignment(View.TEXT_ALIGNMENT_CENTER);
        mProgressBar.setVisibility(View.VISIBLE);
    } else {
        mLabelView.setText(R.string.status_invalid_password);
    }
}
Also used : Activity(android.app.Activity) NfcAdapter(android.nfc.NfcAdapter) InputMethodManager(android.view.inputmethod.InputMethodManager) Tag(android.nfc.Tag)

Aggregations

Tag (android.nfc.Tag)7 NdefMessage (android.nfc.NdefMessage)3 NdefRecord (android.nfc.NdefRecord)2 SuppressLint (android.annotation.SuppressLint)1 Activity (android.app.Activity)1 PendingIntent (android.app.PendingIntent)1 Intent (android.content.Intent)1 NfcAdapter (android.nfc.NfcAdapter)1 ReaderCallback (android.nfc.NfcAdapter.ReaderCallback)1 IsoDep (android.nfc.tech.IsoDep)1 Bundle (android.os.Bundle)1 InputMethodManager (android.view.inputmethod.InputMethodManager)1 IOException (java.io.IOException)1