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);
}
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();
}
}
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();
}
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();
}
}
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);
}
}
Aggregations