am ce6bbfae: More data for testing.

Merge commit 'ce6bbfae018b5629fd86c77b81fc4d8c655fa275' into gingerbread-plus-aosp

* commit 'ce6bbfae018b5629fd86c77b81fc4d8c655fa275':
  More data for testing.
This commit is contained in:
Nick Kralevich
2010-10-05 16:48:56 -07:00
committed by Android Git Automerger
2 changed files with 77 additions and 1 deletions

View File

@@ -21,7 +21,11 @@ import android.app.AlertDialog;
import android.app.Dialog;
import android.content.DialogInterface;
import android.os.Bundle;
import android.util.Log;
import android.widget.Toast;
import com.trustedlogic.trustednfc.android.NfcManager;
import com.trustedlogic.trustednfc.android.NdefMessage;
/**
* @author nnk@google.com (Nick Kralevich)
@@ -32,7 +36,10 @@ public class SaveTag extends Activity implements DialogInterface.OnClickListener
protected void onStart() {
super.onStart();
showDialog(1);
String s = getIntent().getExtras().toString();
NdefMessage msg = getIntent().getParcelableExtra(NfcManager.NDEF_MESSAGE_EXTRA);
String s = toHexString(msg.toByteArray());
Log.d("SaveTag", s);
Toast.makeText(this.getBaseContext(), "SaveTag: " + s, Toast.LENGTH_SHORT).show();
}
@@ -54,4 +61,14 @@ public class SaveTag extends Activity implements DialogInterface.OnClickListener
super.onStop();
dismissDialog(1);
}
private static final char[] hexDigits = "0123456789abcdef".toCharArray();
private static String toHexString(byte[] bytes) {
StringBuilder sb = new StringBuilder(3 * bytes.length);
for (byte b : bytes) {
sb.append("(byte) 0x").append(hexDigits[(b >> 4) & 0xf]).append(hexDigits[b & 0xf]).append(", ");
}
return sb.toString();
}
}

View File

@@ -23,6 +23,7 @@ import android.database.sqlite.SQLiteStatement;
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 java.net.URI;
import java.util.Date;
@@ -44,6 +45,56 @@ public class TagDBHelper extends SQLiteOpenHelper {
private static final String INSERT =
"INSERT INTO NdefMessage (bytes, date) values (?, ?)";
private static final byte[] REAL_NFC_MSG = new byte[] {
(byte) 0xd1,
(byte) 0x02,
(byte) 0x2b,
(byte) 0x53,
(byte) 0x70,
(byte) 0x91,
(byte) 0x01,
(byte) 0x17,
(byte) 0x54,
(byte) 0x02,
(byte) 0x65,
(byte) 0x6e,
(byte) 0x4e,
(byte) 0x46,
(byte) 0x43,
(byte) 0x20,
(byte) 0x46,
(byte) 0x6f,
(byte) 0x72,
(byte) 0x75,
(byte) 0x6d,
(byte) 0x20,
(byte) 0x54,
(byte) 0x79,
(byte) 0x70,
(byte) 0x65,
(byte) 0x20,
(byte) 0x34,
(byte) 0x20,
(byte) 0x54,
(byte) 0x61,
(byte) 0x67,
(byte) 0x51,
(byte) 0x01,
(byte) 0x0c,
(byte) 0x55,
(byte) 0x01,
(byte) 0x6e,
(byte) 0x78,
(byte) 0x70,
(byte) 0x2e,
(byte) 0x63,
(byte) 0x6f,
(byte) 0x6d,
(byte) 0x2f,
(byte) 0x6e,
(byte) 0x66,
(byte) 0x63
};
public TagDBHelper(Context context) {
this(context, "Tags.db");
@@ -71,6 +122,14 @@ public class TagDBHelper extends SQLiteOpenHelper {
insert(db, msg1);
insert(db, msg2);
try {
// A real message obtained from an NFC Forum Type 4 tag.
NdefMessage msg3 = new NdefMessage(REAL_NFC_MSG);
insert(db, msg3);
} catch (NfcException e) {
throw new RuntimeException(e);
}
}
private void insert(SQLiteDatabase db, NdefMessage msg) {