mirror of
https://github.com/apache/cordova-android.git
synced 2025-02-01 02:12:58 +08:00
CB-1005: Can not remove contact phonenumber values
This commit is contained in:
parent
9d4977db00
commit
b97748d3dc
@ -71,6 +71,7 @@ import android.webkit.WebView;
|
||||
* social status updates (see {@link android.provider.ContactsContract.StatusUpdates}).
|
||||
* </ul>
|
||||
*/
|
||||
|
||||
public class ContactAccessorSdk5 extends ContactAccessor {
|
||||
|
||||
/**
|
||||
@ -944,6 +945,16 @@ public class ContactAccessorSdk5 extends ContactAccessor {
|
||||
try {
|
||||
phones = contact.getJSONArray("phoneNumbers");
|
||||
if (phones != null) {
|
||||
// Delete all the phones
|
||||
if (phones.length() == 0) {
|
||||
ops.add(ContentProviderOperation.newDelete(ContactsContract.Data.CONTENT_URI)
|
||||
.withSelection(ContactsContract.Data.RAW_CONTACT_ID + "=? AND " +
|
||||
ContactsContract.Data.MIMETYPE + "=?",
|
||||
new String[] { "" + rawId, ContactsContract.CommonDataKinds.Phone.CONTENT_ITEM_TYPE })
|
||||
.build());
|
||||
}
|
||||
// Modify or add a phone
|
||||
else {
|
||||
for (int i = 0; i < phones.length(); i++) {
|
||||
JSONObject phone = (JSONObject) phones.get(i);
|
||||
String phoneId = getJsonString(phone, "id");
|
||||
@ -970,6 +981,7 @@ public class ContactAccessorSdk5 extends ContactAccessor {
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
} catch (JSONException e) {
|
||||
Log.d(LOG_TAG, "Could not get phone numbers");
|
||||
}
|
||||
@ -979,6 +991,16 @@ public class ContactAccessorSdk5 extends ContactAccessor {
|
||||
try {
|
||||
emails = contact.getJSONArray("emails");
|
||||
if (emails != null) {
|
||||
// Delete all the emails
|
||||
if (emails.length() == 0) {
|
||||
ops.add(ContentProviderOperation.newDelete(ContactsContract.Data.CONTENT_URI)
|
||||
.withSelection(ContactsContract.Data.RAW_CONTACT_ID + "=? AND " +
|
||||
ContactsContract.Data.MIMETYPE + "=?",
|
||||
new String[] { "" + rawId, ContactsContract.CommonDataKinds.Email.CONTENT_ITEM_TYPE })
|
||||
.build());
|
||||
}
|
||||
// Modify or add a email
|
||||
else {
|
||||
for (int i = 0; i < emails.length(); i++) {
|
||||
JSONObject email = (JSONObject) emails.get(i);
|
||||
String emailId = getJsonString(email, "id");
|
||||
@ -1005,6 +1027,7 @@ public class ContactAccessorSdk5 extends ContactAccessor {
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
} catch (JSONException e) {
|
||||
Log.d(LOG_TAG, "Could not get emails");
|
||||
}
|
||||
@ -1014,6 +1037,16 @@ public class ContactAccessorSdk5 extends ContactAccessor {
|
||||
try {
|
||||
addresses = contact.getJSONArray("addresses");
|
||||
if (addresses != null) {
|
||||
// Delete all the addresses
|
||||
if (addresses.length() == 0) {
|
||||
ops.add(ContentProviderOperation.newDelete(ContactsContract.Data.CONTENT_URI)
|
||||
.withSelection(ContactsContract.Data.RAW_CONTACT_ID + "=? AND " +
|
||||
ContactsContract.Data.MIMETYPE + "=?",
|
||||
new String[] { "" + rawId, ContactsContract.CommonDataKinds.StructuredPostal.CONTENT_ITEM_TYPE })
|
||||
.build());
|
||||
}
|
||||
// Modify or add a address
|
||||
else {
|
||||
for (int i = 0; i < addresses.length(); i++) {
|
||||
JSONObject address = (JSONObject) addresses.get(i);
|
||||
String addressId = getJsonString(address, "id");
|
||||
@ -1050,6 +1083,7 @@ public class ContactAccessorSdk5 extends ContactAccessor {
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
} catch (JSONException e) {
|
||||
Log.d(LOG_TAG, "Could not get addresses");
|
||||
}
|
||||
@ -1059,6 +1093,16 @@ public class ContactAccessorSdk5 extends ContactAccessor {
|
||||
try {
|
||||
organizations = contact.getJSONArray("organizations");
|
||||
if (organizations != null) {
|
||||
// Delete all the organizations
|
||||
if (organizations.length() == 0) {
|
||||
ops.add(ContentProviderOperation.newDelete(ContactsContract.Data.CONTENT_URI)
|
||||
.withSelection(ContactsContract.Data.RAW_CONTACT_ID + "=? AND " +
|
||||
ContactsContract.Data.MIMETYPE + "=?",
|
||||
new String[] { "" + rawId, ContactsContract.CommonDataKinds.Organization.CONTENT_ITEM_TYPE })
|
||||
.build());
|
||||
}
|
||||
// Modify or add a organization
|
||||
else {
|
||||
for (int i = 0; i < organizations.length(); i++) {
|
||||
JSONObject org = (JSONObject) organizations.get(i);
|
||||
String orgId = getJsonString(org, "id");
|
||||
@ -1089,6 +1133,7 @@ public class ContactAccessorSdk5 extends ContactAccessor {
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
} catch (JSONException e) {
|
||||
Log.d(LOG_TAG, "Could not get organizations");
|
||||
}
|
||||
@ -1098,6 +1143,16 @@ public class ContactAccessorSdk5 extends ContactAccessor {
|
||||
try {
|
||||
ims = contact.getJSONArray("ims");
|
||||
if (ims != null) {
|
||||
// Delete all the ims
|
||||
if (ims.length() == 0) {
|
||||
ops.add(ContentProviderOperation.newDelete(ContactsContract.Data.CONTENT_URI)
|
||||
.withSelection(ContactsContract.Data.RAW_CONTACT_ID + "=? AND " +
|
||||
ContactsContract.Data.MIMETYPE + "=?",
|
||||
new String[] { "" + rawId, ContactsContract.CommonDataKinds.Im.CONTENT_ITEM_TYPE })
|
||||
.build());
|
||||
}
|
||||
// Modify or add a im
|
||||
else {
|
||||
for (int i = 0; i < ims.length(); i++) {
|
||||
JSONObject im = (JSONObject) ims.get(i);
|
||||
String imId = getJsonString(im, "id");
|
||||
@ -1124,6 +1179,7 @@ public class ContactAccessorSdk5 extends ContactAccessor {
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
} catch (JSONException e) {
|
||||
Log.d(LOG_TAG, "Could not get emails");
|
||||
}
|
||||
@ -1151,8 +1207,19 @@ public class ContactAccessorSdk5 extends ContactAccessor {
|
||||
// Modify urls
|
||||
JSONArray websites = null;
|
||||
try {
|
||||
websites = contact.getJSONArray("websites");
|
||||
websites = contact.getJSONArray("urls");
|
||||
if (websites != null) {
|
||||
// Delete all the websites
|
||||
if (websites.length() == 0) {
|
||||
Log.d(LOG_TAG, "This means we should be deleting all the phone numbers.");
|
||||
ops.add(ContentProviderOperation.newDelete(ContactsContract.Data.CONTENT_URI)
|
||||
.withSelection(ContactsContract.Data.RAW_CONTACT_ID + "=? AND " +
|
||||
ContactsContract.Data.MIMETYPE + "=?",
|
||||
new String[] { "" + rawId, ContactsContract.CommonDataKinds.Website.CONTENT_ITEM_TYPE })
|
||||
.build());
|
||||
}
|
||||
// Modify or add a website
|
||||
else {
|
||||
for (int i = 0; i < websites.length(); i++) {
|
||||
JSONObject website = (JSONObject) websites.get(i);
|
||||
String websiteId = getJsonString(website, "id");
|
||||
@ -1179,6 +1246,7 @@ public class ContactAccessorSdk5 extends ContactAccessor {
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
} catch (JSONException e) {
|
||||
Log.d(LOG_TAG, "Could not get websites");
|
||||
}
|
||||
@ -1201,6 +1269,16 @@ public class ContactAccessorSdk5 extends ContactAccessor {
|
||||
try {
|
||||
photos = contact.getJSONArray("photos");
|
||||
if (photos != null) {
|
||||
// Delete all the photos
|
||||
if (photos.length() == 0) {
|
||||
ops.add(ContentProviderOperation.newDelete(ContactsContract.Data.CONTENT_URI)
|
||||
.withSelection(ContactsContract.Data.RAW_CONTACT_ID + "=? AND " +
|
||||
ContactsContract.Data.MIMETYPE + "=?",
|
||||
new String[] { "" + rawId, ContactsContract.CommonDataKinds.Photo.CONTENT_ITEM_TYPE })
|
||||
.build());
|
||||
}
|
||||
// Modify or add a photo
|
||||
else {
|
||||
for (int i = 0; i < photos.length(); i++) {
|
||||
JSONObject photo = (JSONObject) photos.get(i);
|
||||
String photoId = getJsonString(photo, "id");
|
||||
@ -1228,6 +1306,7 @@ public class ContactAccessorSdk5 extends ContactAccessor {
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
} catch (JSONException e) {
|
||||
Log.d(LOG_TAG, "Could not get photos");
|
||||
}
|
||||
@ -1554,7 +1633,7 @@ public class ContactAccessorSdk5 extends ContactAccessor {
|
||||
// Add urls
|
||||
JSONArray websites = null;
|
||||
try {
|
||||
websites = contact.getJSONArray("websites");
|
||||
websites = contact.getJSONArray("urls");
|
||||
if (websites != null) {
|
||||
for (int i = 0; i < websites.length(); i++) {
|
||||
JSONObject website = (JSONObject) websites.get(i);
|
||||
|
Loading…
Reference in New Issue
Block a user