use of android.nfc.NdefMessage in project android_packages_apps_Settings by omnirom.
the class WriteWifiConfigToNfcDialog method handleWriteNfcEvent.
private void handleWriteNfcEvent(Tag tag) {
Ndef ndef = Ndef.get(tag);
if (ndef != null) {
if (ndef.isWritable()) {
NdefRecord record = NdefRecord.createMime(NFC_TOKEN_MIME_TYPE, hexStringToByteArray(mWpsNfcConfigurationToken));
try {
ndef.connect();
ndef.writeNdefMessage(new NdefMessage(record));
getOwnerActivity().runOnUiThread(new Runnable() {
@Override
public void run() {
mProgressBar.setVisibility(View.GONE);
}
});
setViewText(mLabelView, R.string.status_write_success);
setViewText(mCancelButton, com.android.internal.R.string.done_label);
} catch (IOException e) {
setViewText(mLabelView, R.string.status_failed_to_write);
Log.e(TAG, "Unable to write Wi-Fi config to NFC tag.", e);
return;
} catch (FormatException e) {
setViewText(mLabelView, R.string.status_failed_to_write);
Log.e(TAG, "Unable to write Wi-Fi config to NFC tag.", e);
return;
}
} else {
setViewText(mLabelView, R.string.status_tag_not_writable);
Log.e(TAG, "Tag is not writable");
}
} else {
setViewText(mLabelView, R.string.status_tag_not_writable);
Log.e(TAG, "Tag does not support NDEF");
}
}
use of android.nfc.NdefMessage in project android_packages_apps_Settings by DirtyUnicorns.
the class WriteWifiConfigToNfcDialog method handleWriteNfcEvent.
private void handleWriteNfcEvent(Tag tag) {
Ndef ndef = Ndef.get(tag);
if (ndef != null) {
if (ndef.isWritable()) {
NdefRecord record = NdefRecord.createMime(NFC_TOKEN_MIME_TYPE, hexStringToByteArray(mWpsNfcConfigurationToken));
try {
ndef.connect();
ndef.writeNdefMessage(new NdefMessage(record));
getOwnerActivity().runOnUiThread(new Runnable() {
@Override
public void run() {
mProgressBar.setVisibility(View.GONE);
}
});
setViewText(mLabelView, R.string.status_write_success);
setViewText(mCancelButton, com.android.internal.R.string.done_label);
} catch (IOException e) {
setViewText(mLabelView, R.string.status_failed_to_write);
Log.e(TAG, "Unable to write Wi-Fi config to NFC tag.", e);
return;
} catch (FormatException e) {
setViewText(mLabelView, R.string.status_failed_to_write);
Log.e(TAG, "Unable to write Wi-Fi config to NFC tag.", e);
return;
}
} else {
setViewText(mLabelView, R.string.status_tag_not_writable);
Log.e(TAG, "Tag is not writable");
}
} else {
setViewText(mLabelView, R.string.status_tag_not_writable);
Log.e(TAG, "Tag does not support NDEF");
}
}
use of android.nfc.NdefMessage in project fdroidclient by f-droid.
the class RepoDetailsActivity method processIntent.
private void processIntent(Intent i) {
if (NfcAdapter.ACTION_NDEF_DISCOVERED.equals(i.getAction())) {
Parcelable[] rawMsgs = i.getParcelableArrayExtra(NfcAdapter.EXTRA_NDEF_MESSAGES);
NdefMessage msg = (NdefMessage) rawMsgs[0];
String url = new String(msg.getRecords()[0].getPayload());
Utils.debugLog(TAG, "Got this URL: " + url);
Toast.makeText(this, "Got this URL: " + url, Toast.LENGTH_LONG).show();
Intent intent = new Intent(Intent.ACTION_VIEW, Uri.parse(url));
intent.setClass(this, ManageReposActivity.class);
startActivity(intent);
finish();
}
}
use of android.nfc.NdefMessage in project openhab-android by openhab.
the class OpenHABWriteTagActivity method writeTag.
private void writeTag(Tag tag, String uri) {
Log.d(TAG, "Creating tag object for URI " + uri);
TextView writeTagMessage = findViewById(R.id.write_tag_message);
NdefRecord[] ndefRecords = new NdefRecord[] { NdefRecord.createUri(uri) };
NdefMessage message = new NdefMessage(ndefRecords);
NdefFormatable ndefFormatable = NdefFormatable.get(tag);
if (ndefFormatable != null) {
Log.d(TAG, "Tag is uninitialized, formating");
try {
ndefFormatable.connect();
ndefFormatable.format(message);
ndefFormatable.close();
writeTagMessage.setText(R.string.info_write_tag_finished);
autoCloseActivity();
} catch (IOException | FormatException e) {
Log.e(TAG, "Writing to unformatted tag failed: " + e);
writeTagMessage.setText(R.string.info_write_failed);
}
} else {
Log.d(TAG, "Tag is initialized, writing");
Ndef ndef = Ndef.get(tag);
if (ndef != null) {
try {
Log.d(TAG, "Connecting");
ndef.connect();
Log.d(TAG, "Writing");
if (ndef.isWritable()) {
ndef.writeNdefMessage(message);
}
Log.d(TAG, "Closing");
ndef.close();
writeTagMessage.setText(R.string.info_write_tag_finished);
autoCloseActivity();
} catch (IOException | FormatException e) {
Log.e(TAG, "Writing to formatted tag failed: " + e);
writeTagMessage.setText(R.string.info_write_failed);
}
} else {
Log.e(TAG, "Ndef == null");
writeTagMessage.setText(R.string.info_write_failed);
}
}
}
use of android.nfc.NdefMessage in project weiciyuan by qii.
the class UserInfoActivity method processIntent.
private void processIntent(Intent intent) {
Parcelable[] rawMsgs = intent.getParcelableArrayExtra(NfcAdapter.EXTRA_NDEF_MESSAGES);
// only one message sent during the beam
NdefMessage msg = (NdefMessage) rawMsgs[0];
Toast.makeText(this, new String(msg.getRecords()[0].getPayload()), Toast.LENGTH_SHORT).show();
bean = new UserBean();
bean.setScreen_name(new String(msg.getRecords()[0].getPayload()));
}
Aggregations