OSDN Git Service

Have TagBroadcastReceiver start the SaveTag activity.
authorNick Kralevich <nnk@google.com>
Tue, 5 Oct 2010 22:26:04 +0000 (15:26 -0700)
committerNick Kralevich <nnk@google.com>
Tue, 5 Oct 2010 22:28:45 +0000 (15:28 -0700)
Change-Id: I6dc8757ca7eec87efe622b0b2688dd29c5883185

apps/Tag/src/com/android/apps/tag/TagBroadcastReceiver.java

index 015e897..d576bdb 100644 (file)
@@ -19,14 +19,12 @@ package com.android.apps.tag;
 import android.content.BroadcastReceiver;
 import android.content.Context;
 import android.content.Intent;
-import android.widget.Toast;
 import com.trustedlogic.trustednfc.android.NdefMessage;
-import com.trustedlogic.trustednfc.android.NdefRecord;
 import com.trustedlogic.trustednfc.android.NfcManager;
 
 /**
- * This class doesn't work.  Sorry.  Think of this class as pseudo
- * code for now.
+ * When we receive a new NDEF tag, start the activity to
+ * process the tag.
  */
 public class TagBroadcastReceiver extends BroadcastReceiver {
 
@@ -34,19 +32,10 @@ public class TagBroadcastReceiver extends BroadcastReceiver {
     public void onReceive(Context context, Intent intent) {
         if (intent.getAction().equals(NfcManager.NDEF_TAG_DISCOVERED_ACTION)) {
             NdefMessage msg = intent.getParcelableExtra(NfcManager.NDEF_MESSAGE_EXTRA);
-            Toast.makeText(context, "got a new message", Toast.LENGTH_SHORT).show();
-            insertIntoDb(msg);
+            Intent i = new Intent(context, SaveTag.class)
+                    .putExtra(NfcManager.NDEF_MESSAGE_EXTRA, msg)
+                    .addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
+            context.startActivity(i);
         }
     }
-
-    private void insertIntoDb(NdefMessage msg) {
-        for (NdefRecord record : msg.getRecords()) {
-            insertIntoRecordDb(record.getType(), record.getPayload());
-        }
-    }
-
-    private void insertIntoRecordDb(byte[] type, byte[] payload) {
-        // do something...
-    }
-
 }