mirror of
https://github.com/apache/cordova-android.git
synced 2025-02-27 04:42:51 +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}).
|
* social status updates (see {@link android.provider.ContactsContract.StatusUpdates}).
|
||||||
* </ul>
|
* </ul>
|
||||||
*/
|
*/
|
||||||
|
|
||||||
public class ContactAccessorSdk5 extends ContactAccessor {
|
public class ContactAccessorSdk5 extends ContactAccessor {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -944,6 +945,16 @@ public class ContactAccessorSdk5 extends ContactAccessor {
|
|||||||
try {
|
try {
|
||||||
phones = contact.getJSONArray("phoneNumbers");
|
phones = contact.getJSONArray("phoneNumbers");
|
||||||
if (phones != null) {
|
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++) {
|
for (int i = 0; i < phones.length(); i++) {
|
||||||
JSONObject phone = (JSONObject) phones.get(i);
|
JSONObject phone = (JSONObject) phones.get(i);
|
||||||
String phoneId = getJsonString(phone, "id");
|
String phoneId = getJsonString(phone, "id");
|
||||||
@ -970,6 +981,7 @@ public class ContactAccessorSdk5 extends ContactAccessor {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
} catch (JSONException e) {
|
} catch (JSONException e) {
|
||||||
Log.d(LOG_TAG, "Could not get phone numbers");
|
Log.d(LOG_TAG, "Could not get phone numbers");
|
||||||
}
|
}
|
||||||
@ -979,6 +991,16 @@ public class ContactAccessorSdk5 extends ContactAccessor {
|
|||||||
try {
|
try {
|
||||||
emails = contact.getJSONArray("emails");
|
emails = contact.getJSONArray("emails");
|
||||||
if (emails != null) {
|
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++) {
|
for (int i = 0; i < emails.length(); i++) {
|
||||||
JSONObject email = (JSONObject) emails.get(i);
|
JSONObject email = (JSONObject) emails.get(i);
|
||||||
String emailId = getJsonString(email, "id");
|
String emailId = getJsonString(email, "id");
|
||||||
@ -1005,6 +1027,7 @@ public class ContactAccessorSdk5 extends ContactAccessor {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
} catch (JSONException e) {
|
} catch (JSONException e) {
|
||||||
Log.d(LOG_TAG, "Could not get emails");
|
Log.d(LOG_TAG, "Could not get emails");
|
||||||
}
|
}
|
||||||
@ -1014,6 +1037,16 @@ public class ContactAccessorSdk5 extends ContactAccessor {
|
|||||||
try {
|
try {
|
||||||
addresses = contact.getJSONArray("addresses");
|
addresses = contact.getJSONArray("addresses");
|
||||||
if (addresses != null) {
|
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++) {
|
for (int i = 0; i < addresses.length(); i++) {
|
||||||
JSONObject address = (JSONObject) addresses.get(i);
|
JSONObject address = (JSONObject) addresses.get(i);
|
||||||
String addressId = getJsonString(address, "id");
|
String addressId = getJsonString(address, "id");
|
||||||
@ -1050,6 +1083,7 @@ public class ContactAccessorSdk5 extends ContactAccessor {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
} catch (JSONException e) {
|
} catch (JSONException e) {
|
||||||
Log.d(LOG_TAG, "Could not get addresses");
|
Log.d(LOG_TAG, "Could not get addresses");
|
||||||
}
|
}
|
||||||
@ -1059,6 +1093,16 @@ public class ContactAccessorSdk5 extends ContactAccessor {
|
|||||||
try {
|
try {
|
||||||
organizations = contact.getJSONArray("organizations");
|
organizations = contact.getJSONArray("organizations");
|
||||||
if (organizations != null) {
|
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++) {
|
for (int i = 0; i < organizations.length(); i++) {
|
||||||
JSONObject org = (JSONObject) organizations.get(i);
|
JSONObject org = (JSONObject) organizations.get(i);
|
||||||
String orgId = getJsonString(org, "id");
|
String orgId = getJsonString(org, "id");
|
||||||
@ -1089,6 +1133,7 @@ public class ContactAccessorSdk5 extends ContactAccessor {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
} catch (JSONException e) {
|
} catch (JSONException e) {
|
||||||
Log.d(LOG_TAG, "Could not get organizations");
|
Log.d(LOG_TAG, "Could not get organizations");
|
||||||
}
|
}
|
||||||
@ -1098,6 +1143,16 @@ public class ContactAccessorSdk5 extends ContactAccessor {
|
|||||||
try {
|
try {
|
||||||
ims = contact.getJSONArray("ims");
|
ims = contact.getJSONArray("ims");
|
||||||
if (ims != null) {
|
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++) {
|
for (int i = 0; i < ims.length(); i++) {
|
||||||
JSONObject im = (JSONObject) ims.get(i);
|
JSONObject im = (JSONObject) ims.get(i);
|
||||||
String imId = getJsonString(im, "id");
|
String imId = getJsonString(im, "id");
|
||||||
@ -1124,6 +1179,7 @@ public class ContactAccessorSdk5 extends ContactAccessor {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
} catch (JSONException e) {
|
} catch (JSONException e) {
|
||||||
Log.d(LOG_TAG, "Could not get emails");
|
Log.d(LOG_TAG, "Could not get emails");
|
||||||
}
|
}
|
||||||
@ -1151,8 +1207,19 @@ public class ContactAccessorSdk5 extends ContactAccessor {
|
|||||||
// Modify urls
|
// Modify urls
|
||||||
JSONArray websites = null;
|
JSONArray websites = null;
|
||||||
try {
|
try {
|
||||||
websites = contact.getJSONArray("websites");
|
websites = contact.getJSONArray("urls");
|
||||||
if (websites != null) {
|
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++) {
|
for (int i = 0; i < websites.length(); i++) {
|
||||||
JSONObject website = (JSONObject) websites.get(i);
|
JSONObject website = (JSONObject) websites.get(i);
|
||||||
String websiteId = getJsonString(website, "id");
|
String websiteId = getJsonString(website, "id");
|
||||||
@ -1179,6 +1246,7 @@ public class ContactAccessorSdk5 extends ContactAccessor {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
} catch (JSONException e) {
|
} catch (JSONException e) {
|
||||||
Log.d(LOG_TAG, "Could not get websites");
|
Log.d(LOG_TAG, "Could not get websites");
|
||||||
}
|
}
|
||||||
@ -1201,6 +1269,16 @@ public class ContactAccessorSdk5 extends ContactAccessor {
|
|||||||
try {
|
try {
|
||||||
photos = contact.getJSONArray("photos");
|
photos = contact.getJSONArray("photos");
|
||||||
if (photos != null) {
|
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++) {
|
for (int i = 0; i < photos.length(); i++) {
|
||||||
JSONObject photo = (JSONObject) photos.get(i);
|
JSONObject photo = (JSONObject) photos.get(i);
|
||||||
String photoId = getJsonString(photo, "id");
|
String photoId = getJsonString(photo, "id");
|
||||||
@ -1228,6 +1306,7 @@ public class ContactAccessorSdk5 extends ContactAccessor {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
} catch (JSONException e) {
|
} catch (JSONException e) {
|
||||||
Log.d(LOG_TAG, "Could not get photos");
|
Log.d(LOG_TAG, "Could not get photos");
|
||||||
}
|
}
|
||||||
@ -1554,7 +1633,7 @@ public class ContactAccessorSdk5 extends ContactAccessor {
|
|||||||
// Add urls
|
// Add urls
|
||||||
JSONArray websites = null;
|
JSONArray websites = null;
|
||||||
try {
|
try {
|
||||||
websites = contact.getJSONArray("websites");
|
websites = contact.getJSONArray("urls");
|
||||||
if (websites != null) {
|
if (websites != null) {
|
||||||
for (int i = 0; i < websites.length(); i++) {
|
for (int i = 0; i < websites.length(); i++) {
|
||||||
JSONObject website = (JSONObject) websites.get(i);
|
JSONObject website = (JSONObject) websites.get(i);
|
||||||
|
Loading…
Reference in New Issue
Block a user