use of android.nfc.FormatException 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.FormatException 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.FormatException 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.FormatException in project platform_packages_apps_Settings by BlissRoms.
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");
}
}
Aggregations