Hello,
Can you please share some example of ContentProviderOperation.NewInsert ?
Sure, before you insert contact, please add following permission in the AndroidManifest.xml
for Android.
<uses-permission android:name="android.permission.READ_CONTACTS" />
<uses-permission android:name="android.permission.WRITE_CONTACTS" />
Then, you can request this permission by Permissions.RequestAsync<Permissions.ContactsWrite>();
. If the permission is granted, you can insert contacts information.
PermissionStatus status = await Permissions.RequestAsync<Permissions.ContactsWrite>();
if (status == PermissionStatus.Granted)
{
#if ANDROID
Context context = Platform.AppContext;
/* Add data to raw_contacts and get the added ID number*/
Android.Net.Uri uri = Android.Net.Uri.Parse("content://com.android.contacts/raw_contacts");
ContentResolver resolver = context.ContentResolver;
ContentValues values = new ContentValues();
long contactId = ContentUris.ParseId(resolver.Insert(uri, values));
// Add Name MyTestName for testing.
uri = Android.Net.Uri.Parse("content://com.android.contacts/data");
values.Put("raw_contact_id", contactId);
values.Put("mimetype", "vnd.android.cursor.item/name");
values.Put("data2", "MyTestName");
resolver.Insert(uri, values);
// Add telephone Numer 1234579 for testing
values.Clear();
values.Put("raw_contact_id", contactId);
values.Put("mimetype", "vnd.android.cursor.item/phone_v2");
values.Put("data2", "2");
values.Put("data1", "1234579");
resolver.Insert(uri, values);
#endif
Best Regards,
Leon Lu
If the answer is the right solution, please click "Accept Answer" and kindly upvote it. If you have extra questions about this answer, please click "Comment".
Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.