import com.google.common.collect.ImmutableBiMap;
import com.google.common.collect.Iterables;
import com.google.common.primitives.Bytes;
-import com.trustedlogic.trustednfc.android.NdefMessage;
-import com.trustedlogic.trustednfc.android.NdefRecord;
+import android.nfc.NdefMessage;
+import android.nfc.NdefRecord;
import java.io.UnsupportedEncodingException;
import java.net.URI;
*/
byte[] payload = Bytes.concat(new byte[] { 0x00 }, uriBytes);
- return new NdefRecord(NdefRecord.TNF_WELL_KNOWN_TYPE,
- NdefRecord.TYPE_URI, EMPTY, payload);
+ return new NdefRecord(NdefRecord.TNF_WELL_KNOWN,
+ NdefRecord.RTD_URI, EMPTY, payload);
}
/**
* record containing a URI.
*/
public static URI toURI(NdefRecord record) throws URISyntaxException {
- Preconditions.checkArgument(record.getTnf() == NdefRecord.TNF_WELL_KNOWN_TYPE);
- Preconditions.checkArgument(Arrays.equals(record.getType(), NdefRecord.TYPE_URI));
+ Preconditions.checkArgument(record.getTnf() == NdefRecord.TNF_WELL_KNOWN);
+ Preconditions.checkArgument(Arrays.equals(record.getType(), NdefRecord.RTD_URI));
byte[] payload = record.getPayload();
import android.app.AlertDialog;
import android.app.Dialog;
import android.content.DialogInterface;
+import android.nfc.NdefMessage;
+import android.nfc.NdefTag;
+import android.nfc.NfcAdapter;
import android.os.Bundle;
import android.util.Log;
import android.view.WindowManager;
* An {@code Activity} which handles a broadcast of a new tag that the device just discovered.
*/
public class SaveTag extends Activity implements DialogInterface.OnClickListener {
+ private static final String TAG = "SaveTag";
@Override
protected void onStart() {
);
showDialog(1);
- NdefMessage msg = getIntent().getParcelableExtra(NfcManager.NDEF_MESSAGE_EXTRA);
+ NdefTag tag = getIntent().getParcelableExtra(NfcAdapter.EXTRA_TAG);
+ NdefMessage[] msgs = tag.getNdefMessages();
- String s = toHexString(msg.toByteArray());
+ if (msgs.length == 0) {
+ Log.d(TAG, "No NDEF messages");
+ return;
+ }
+ if (msgs.length > 1) {
+ Log.d(TAG, "Multiple NDEF messages, only saving first");
+ }
+ String s = toHexString(msgs[0].toByteArray());
Log.d("SaveTag", s);
Toast.makeText(this.getBaseContext(), "SaveTag: " + s, Toast.LENGTH_SHORT).show();
}
import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
-import com.trustedlogic.trustednfc.android.NdefMessage;
-import com.trustedlogic.trustednfc.android.NfcManager;
+import android.nfc.NdefTag;
+
+import android.nfc.NdefMessage;
+import android.nfc.NfcAdapter;
/**
* When we receive a new NDEF tag, start the activity to
@Override
public void onReceive(Context context, Intent intent) {
- if (intent.getAction().equals(NfcManager.NDEF_TAG_DISCOVERED_ACTION)) {
- NdefMessage msg = intent.getParcelableExtra(NfcManager.NDEF_MESSAGE_EXTRA);
+ if (intent.getAction().equals(NfcAdapter.ACTION_NDEF_TAG_DISCOVERED)) {
+ NdefTag tag = intent.getParcelableExtra(NfcAdapter.EXTRA_TAG);
Intent i = new Intent(context, SaveTag.class)
- .putExtra(NfcManager.NDEF_MESSAGE_EXTRA, msg)
+ .putExtra(NfcAdapter.EXTRA_TAG, tag)
.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
context.startActivity(i);
}
package com.android.apps.tag;
import com.google.common.annotations.VisibleForTesting;
-import com.trustedlogic.trustednfc.android.NdefMessage;
-import com.trustedlogic.trustednfc.android.NdefRecord;
-import com.trustedlogic.trustednfc.android.NfcException;
+import android.nfc.NdefMessage;
+import android.nfc.NdefRecord;
+import android.nfc.FormatException;
import android.content.Context;
import android.database.sqlite.SQLiteDatabase;
// A real message obtained from an NFC Forum Type 4 tag.
NdefMessage msg3 = new NdefMessage(REAL_NFC_MSG);
insert(db, msg3, false);
- } catch (NfcException e) {
+ } catch (FormatException e) {
throw new RuntimeException(e);
}
}