Update Tag app for API changes.

Change-Id: Idecfee21ee58f7a19d5dcbae39c231b8e8d96095
Signed-off-by: Nick Pelly <npelly@google.com>
This commit is contained in:
Nick Pelly
2010-10-12 15:41:10 -07:00
parent 5fed2354d2
commit 1d5707b5a8
4 changed files with 31 additions and 17 deletions

View File

@@ -22,8 +22,8 @@ import com.google.common.collect.BiMap;
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;
@@ -105,8 +105,8 @@ public class NdefUtil {
*/
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);
}
/**
@@ -122,8 +122,8 @@ public class NdefUtil {
* 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();

View File

@@ -23,6 +23,9 @@ import android.app.Activity;
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;
@@ -32,6 +35,7 @@ import android.widget.Toast;
* 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() {
@@ -46,9 +50,17 @@ public class SaveTag extends Activity implements DialogInterface.OnClickListener
);
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();
}

View File

@@ -19,8 +19,10 @@ package com.android.apps.tag;
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
@@ -30,10 +32,10 @@ public class TagBroadcastReceiver extends BroadcastReceiver {
@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);
}

View File

@@ -17,9 +17,9 @@
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;
@@ -146,7 +146,7 @@ public class TagDBHelper extends SQLiteOpenHelper {
// 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);
}
}