What permission do you need to add to add a contact?

I am trying to add a new contact to an Android phone. For this, I use the following code.

ContentValues values = new ContentValues(); values.put(Phone.RAW_CONTACT_ID, "jadeja"); values.put(Phone.NUMBER, 1234567890); values.put(Phone.TYPE, Phone.TYPE_MOBILE); Uri uri = getContentResolver().insert(Phone.CONTENT_URI, values); 

But this action closes the application, and inside the "LogCat" it shows that the security permission is denied. Is there any way to achieve this?

+4
source share
3 answers

This should be added in the manifest WRITE_CONTACTS

+5
source

Add the following to your AndroidManifest.XML file:

 <uses-permission android:name="android.permission.WRITE_CONTACTS"/> 
+5
source

Add these permissions to the android Maifest.xml file:

 <uses-permission android:name="android.permission.READ_PHONE_STATE" /> <uses-permission android:name="android.permission.WRITE_CONTACTS" /> 
+1
source

Source: https://habr.com/ru/post/1399971/


All Articles