Home  >  Forum  >  Android
Post New Query

UnsupportedOperationException: URI: content://com.android.contacts/data/phones


joined on
March 22,2015
Asked on July 04,2015
Hi,
I am creating android application too insert contacts. My code snippet is given as below.

ContentValues cv=new ContentValues();
this.grantUriPermission("com.example.contactsdemo",Uri.parse("content://com.android.contacts/contacts"), MODE_WORLD_WRITEABLE);
for (int i = 0; i < names.length; i++) {
    cv.put(ContactsContract.CommonDataKinds.Phone.DISPLAY_NAME,names[i]);
    cv.put(ContactsContract.CommonDataKinds.Phone.NUMBER,numbers[i]);
    cv.put(ContactsContract.CommonDataKinds.Phone._ID,ids[i]);
    u = getContentResolver().insert(ContactsContract.CommonDataKinds.Phone.CONTENT_URI, cv);
}

and getting error. How to correct error.

Caused by: java.lang.UnsupportedOperationException: URI: content://com.android.contacts/data/phones, calling user:, calling package
E/AndroidRuntime(781): at android.database.DatabaseUtils.readExceptionFromParcel(DatabaseUtils.java:169)
E/AndroidRuntime(781): at android.database.DatabaseUtils.readExceptionFromParcel(DatabaseUtils.java:137)
E/AndroidRuntime(781): at android.content.ContentProviderProxy.insert(ContentProviderNative.java:475)
E/AndroidRuntime(781): at android.content.ContentResolver.insert(ContentResolver.java:1190)





joined on
October 10,2013
Replied on July 04,2015

Find the sample code to write contacts.

contentProviderOperations.add(ContentProviderOperation.newInsert(RawContacts.CONTENT_URI)
        .withValue(RawContacts.ACCOUNT_TYPE, null).withValue(RawContacts.ACCOUNT_NAME, null).build());   
//insert contact display name using Data.CONTENT_URI
contentProviderOperations.add(ContentProviderOperation.newInsert(Data.CONTENT_URI)
        .withValueBackReference(Data.RAW_CONTACT_ID, 0).withValue(Data.MIMETYPE, StructuredName.CONTENT_ITEM_TYPE)
        .withValue(StructuredName.DISPLAY_NAME, displayName).build());
//insert mobile number using Data.CONTENT_URI
contentProviderOperations.add(ContentProviderOperation.newInsert(Data.CONTENT_URI)
        .withValueBackReference(ContactsContract.Data.RAW_CONTACT_ID, 0).withValue(Data.MIMETYPE, Phone.CONTENT_ITEM_TYPE)
        .withValue(Phone.NUMBER, number).withValue(Phone.TYPE, Phone.TYPE_MOBILE).build()); 


Find the link.


Write Answer








Copyright ©2017 concretepage.com, all rights reserved |Privacy Policy | Contact Us