How to remove a contact with a specified phone number

Problems with WiFi, SQLite ,Bluetooth, WiMax, Proxies, etc...

How to remove a contact with a specified phone number

Postby silverburgh.meryl » Sun Feb 08, 2009 11:22 pm

How to remove a contact with a specified phone number?

I try this:

String phone ="1234567";
context.getContentResolver().delete(Contacts.Phones.CONTENT_URI,
phone, null);

But I get an error with this:
java.lang.UnsupportedOperationException: Cannot delete that URL:
content://contacts/phones
at android.database.DatabaseUtils.readExceptionFromParcel(DatabaseUtils.java:130)
at android.database.DatabaseUtils.readExceptionFromParcel(DatabaseUtils.java:110)
at android.content.ContentProviderProxy.delete(ContentProviderNative.java:362)
at android.content.ContentResolver.delete(ContentResolver.java:386)
at com.mytest.TestUtil.removeContact(TestUtil.java:87)


Thank you for any pointers.
silverburgh.meryl
Junior Developer
Junior Developer
 
Posts: 23
Joined: Sun Feb 08, 2009 11:17 pm

Top

Postby MrSnowflake » Mon Feb 09, 2009 12:14 am

You might wanna try forming a decent SQL select argument for the delete() method:
context.getContentResolver().delete(Contacts.Phones.CONTENT_URI,
Contacts.PhoneNumberColumn+"=?", new String[] {phone});
User avatar
MrSnowflake
Moderator
Moderator
 
Posts: 1439
Joined: Sat Feb 16, 2008 3:11 pm
Location: Flanders, Belgium

Postby silverburgh.meryl » Mon Feb 09, 2009 2:03 am

Thanks. I tried your suggestion (modified to Contacts.PhonesColumns.NUMBER)

I set get the same error:
Code: Select all
ava.lang.UnsupportedOperationException: Cannot delete that URL: content://contacts/phones
   at android.database.DatabaseUtils.readExceptionFromParcel(DatabaseUtils.java:130)
   at android.database.DatabaseUtils.readExceptionFromParcel(DatabaseUtils.java:110)
   at android.content.ContentProviderProxy.delete(ContentProviderNative.java:362)
   at android.content.ContentResolver.delete(ContentResolver.java:386)


Code: Select all
   private void removeContact(Context context, String phone) {
        //context.getContentResolver().delete(Contacts.Phones.CONTENT_URI, phone, null);
        context.getContentResolver().delete(Contacts.Phones.CONTENT_URI,
              Contacts.PhonesColumns.NUMBER+"=?", new String[] {phone});
   }

silverburgh.meryl
Junior Developer
Junior Developer
 
Posts: 23
Joined: Sun Feb 08, 2009 11:17 pm

Cannot delete that URL: content://contacts/phones

Postby EMMNS » Thu Mar 19, 2009 6:55 pm

I am having the same problem now, how did you solve it?
I have the permission done in the manifest.xml too
Syntax: [ Download ] [ Hide ]
Using xml Syntax Highlighting
  1.  
  2. <uses-permission android:name="android.permission.READ_CONTACTS" />
  3.  
  4.         <uses-permission android:name="android.permission.WRITE_CONTACTS" />
  5.  
  6.  
Parsed in 0.001 seconds, using GeSHi 1.0.8.4


and here is my code:
Syntax: [ Download ] [ Hide ]
Using java Syntax Highlighting
  1.  
  2. public int deleteContact() {
  3.  
  4.  
  5.  
  6.                 int isOK=0;
  7.  
  8.                 try{
  9.  
  10.                         isOK=ClientLoader.this.getContentResolver().delete(
  11.  
  12.                                         Contacts.Phones.CONTENT_URI, null, null);
  13.  
  14.                 }catch (Exception e){
  15.  
  16.                         System.out.println(e.toString());
  17.  
  18.                 }
  19.  
  20.                
  21.  
  22.                 return isOK;
  23.  
  24.         }
  25.  
  26.  
Parsed in 0.031 seconds, using GeSHi 1.0.8.4

I have the try/catch just for debuging

but still get the same error:
ava.lang.UnsupportedOperationException: Cannot delete that URL: content://contacts/phones


did you find a solution for it ?

thanx

EMMNS
EMMNS
Freshman
Freshman
 
Posts: 7
Joined: Mon Mar 02, 2009 9:13 pm

Top

Return to Networking & Database Problems

Who is online

Users browsing this forum: No registered users and 13 guests