Initial, but not very nice, sharing of text via My Tag.
TODOs
- prompt user for wiping existing tags
- launch MyTag within the TagBrowser
- add support for images / parsing URL's / contacts
Change-Id: I9f4d9b2ee5a3a7345ea269acfd8f9bb5c3511542
diff --git a/AndroidManifest.xml b/AndroidManifest.xml
index d12185b..aa3f040 100644
--- a/AndroidManifest.xml
+++ b/AndroidManifest.xml
@@ -61,7 +61,13 @@
</intent-filter>
</activity>
- <activity android:name="MyTagActivity" />
+ <activity android:name="MyTagActivity" android:label="@string/tab_my_tag">
+ <intent-filter>
+ <action android:name="android.intent.action.SEND"/>
+ <category android:name="android.intent.category.DEFAULT"/>
+ <data android:mimeType="text/plain" />
+ </intent-filter>
+ </activity>
<service android:name="TagService" />
diff --git a/src/com/android/apps/tag/MyTagActivity.java b/src/com/android/apps/tag/MyTagActivity.java
index 38effaa..cac538c 100644
--- a/src/com/android/apps/tag/MyTagActivity.java
+++ b/src/com/android/apps/tag/MyTagActivity.java
@@ -23,6 +23,7 @@
import com.google.common.collect.Lists;
import android.app.Activity;
+import android.content.Intent;
import android.nfc.NdefMessage;
import android.nfc.NdefRecord;
import android.nfc.NfcAdapter;
@@ -65,27 +66,39 @@
public void onStart() {
super.onStart();
- // Populate tag editor from stored tag info.
NdefMessage localMessage = NfcAdapter.getDefaultAdapter().getLocalNdefMessage();
- if (localMessage == null) {
+
+ if (Intent.ACTION_SEND.equals(getIntent().getAction())) {
+ if (localMessage != null) {
+ // TODO: prompt user for confirmation about wiping their old tag.
+ }
+
+ String title = getIntent().getStringExtra(Intent.EXTRA_SUBJECT);
+ String text = getIntent().getStringExtra(Intent.EXTRA_TEXT);
+
+ mEnabled.setChecked(true);
+ mTitleView.setText((title == null) ? "" : title);
+ mTextView.setText((text == null) ? "" : text);
+
+ } else if (localMessage == null) {
mEnabled.setChecked(false);
return;
+
+ } else {
+ // Locally stored message.
+ ParsedNdefMessage parsed = NdefMessageParser.parse(localMessage);
+ List<ParsedNdefRecord> records = parsed.getRecords();
+
+ // There is always a "Title" and a "Text" record for My Tag.
+ if (records.size() < 2) {
+ Log.w(LOG_TAG, "Local record not in expected format");
+ return;
+ }
+ mEnabled.setChecked(true);
+ mTitleView.setText(((TextRecord) records.get(0)).getText());
+ mTextView.setText(((TextRecord) records.get(1)).getText());
}
- mEnabled.setChecked(true);
- ParsedNdefMessage parsed = NdefMessageParser.parse(localMessage);
-
- // There is always a "Title" and a "Text" record for the local message, if it exists.
- List<ParsedNdefRecord> records = parsed.getRecords();
- if (records.size() < 2) {
- Log.w(LOG_TAG, "Local record not in expected format");
- return;
- }
- TextRecord titleRecord = (TextRecord) records.get(0);
- TextRecord textRecord = (TextRecord) records.get(1);
-
- mTitleView.setText(titleRecord.getText());
- mTextView.setText(textRecord.getText());
}
/**