Update Contacts for improved NDEF APIs
o Can always assume one NDEF message with one NDEF record is present.
o intent.getType() will always be lowercase.
Change-Id: I59541ba55d378a9f2bb6ed0c24b2f8cc0f4474dd
diff --git a/AndroidManifest.xml b/AndroidManifest.xml
index f2264d1..43fd693 100644
--- a/AndroidManifest.xml
+++ b/AndroidManifest.xml
@@ -568,7 +568,6 @@
<data android:mimeType="text/directory" />
<data android:mimeType="text/vcard" />
<data android:mimeType="text/x-vcard" />
- <data android:mimeType="text/x-vCard" />
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
</activity>
@@ -580,7 +579,6 @@
<action android:name="android.nfc.action.NDEF_DISCOVERED" />
<data android:mimeType="text/vcard" />
<data android:mimeType="text/x-vcard" />
- <data android:mimeType="text/x-vCard" />
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
</activity>
diff --git a/src/com/android/contacts/NfcHandler.java b/src/com/android/contacts/NfcHandler.java
index ee3e002..1ae72be 100644
--- a/src/com/android/contacts/NfcHandler.java
+++ b/src/com/android/contacts/NfcHandler.java
@@ -89,9 +89,8 @@
ndefBytes.write(buffer, 0, r);
}
- NdefRecord vcardRecord = new NdefRecord(NdefRecord.TNF_MIME_MEDIA,
- "text/x-vCard".getBytes(), new byte[]{}, ndefBytes.toByteArray());
- return new NdefMessage(new NdefRecord[] {vcardRecord});
+ NdefRecord record = NdefRecord.createMime("text/x-vcard", ndefBytes.toByteArray());
+ return new NdefMessage(record);
} catch (IOException e) {
Log.e(TAG, "IOException creating vcard.");
return null;
diff --git a/src/com/android/contacts/vcard/NfcImportVCardActivity.java b/src/com/android/contacts/vcard/NfcImportVCardActivity.java
index d182cfd..c3a55d2 100644
--- a/src/com/android/contacts/vcard/NfcImportVCardActivity.java
+++ b/src/com/android/contacts/vcard/NfcImportVCardActivity.java
@@ -154,25 +154,20 @@
if (!NfcAdapter.ACTION_NDEF_DISCOVERED.equals(intent.getAction())) {
Log.w(TAG, "Unknowon intent " + intent);
finish();
- }
-
- NdefMessage msg = (NdefMessage) intent.getParcelableArrayExtra(
- NfcAdapter.EXTRA_NDEF_MESSAGES)[0];
- NdefRecord records[] = msg.getRecords();
- if (records == null || records.length == 0) {
- Log.w(TAG, "No records " + intent);
- finish();
- }
-
- NdefRecord record = records[0];
- String type = new String(record.getType(), Charset.forName("UTF8"));
- if (record.getTnf() != NdefRecord.TNF_MIME_MEDIA ||
- (!"text/x-vcard".equalsIgnoreCase(type) && !"text/vcard".equals(type))) {
- Log.w(TAG, "Not a vcard");
- //setStatus(getString(R.string.fail_reason_not_supported));
return;
}
- mRecord = record;
+
+ String type = intent.getType();
+ if (type == null ||
+ (!"text/x-vcard".equals(type) && !"text/vcard".equals(type))) {
+ Log.w(TAG, "Not a vcard");
+ //setStatus(getString(R.string.fail_reason_not_supported));
+ finish();
+ return;
+ }
+ NdefMessage msg = (NdefMessage) intent.getParcelableArrayExtra(
+ NfcAdapter.EXTRA_NDEF_MESSAGES)[0];
+ mRecord = msg.getRecords()[0];
final AccountTypeManager accountTypes = AccountTypeManager.getInstance(this);
final List<AccountWithDataSet> accountList = accountTypes.getAccounts(true);