Android Question Android 11 error writing contacts: java.lang.SecurityException

walt61

Active Member
Licensed User
I'm puzzled. When writing contacts (trying to make any kind of modifications to contacts data) I'm getting the below error; the code works fine on Android 7, but not on my new toy with Android 11 (Xiaomi Redmi Note 10), B4A 10.90:

java.lang.SecurityException: Permission Denial: writing com.android.providers.contacts.ContactsProvider2 uri content://com.android.contacts/raw_contacts from pid=25498, uid=10316 requires android.permission.WRITE_CONTACTS, or grantUriPermission()
at android.os.Parcel.createExceptionOrNull(Parcel.java:2376)
at android.os.Parcel.createException(Parcel.java:2360)
at android.os.Parcel.readException(Parcel.java:2343)
at android.database.DatabaseUtils.readExceptionFromParcel(DatabaseUtils.java:190)
at android.database.DatabaseUtils.readExceptionFromParcel(DatabaseUtils.java:142)
at android.content.ContentProviderProxy.insert(ContentProviderNative.java:549)
at android.content.ContentResolver.insert(ContentResolver.java:2177)
at android.content.ContentResolver.insert(ContentResolver.java:2138)
at anywheresoftware.b4a.objects.ContentResolverWrapper.Insert(ContentResolverWrapper.java:75)
at b4a.contactserror.wmcontactsutils._insertcontact(wmcontactsutils.java:1815)
at b4a.contactserror.b4xmainpage._button1_click(b4xmainpage.java:112)
at java.lang.reflect.Method.invoke(Native Method)
at anywheresoftware.b4a.BA.raiseEvent2(BA.java:213)
at anywheresoftware.b4a.BA.raiseEvent(BA.java:193)
at anywheresoftware.b4a.objects.ViewWrapper$1.onClick(ViewWrapper.java:80)
at android.view.View.performClick(View.java:7568)
at android.view.View.performClickInternal(View.java:7545)
at android.view.View.access$3600(View.java:834)
at android.view.View$PerformClick.run(View.java:28706)
at android.os.Handler.handleCallback(Handler.java:938)
at android.os.Handler.dispatchMessage(Handler.java:99)
at android.os.Looper.loop(Looper.java:236)
at android.app.ActivityThread.main(ActivityThread.java:8047)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:600)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:967)

RuntimePermissions PERMISSION_READ_CONTACTS and PERMISSION_WRITE_CONTACTS have been requested and granted, and the Manifest contains AddPermission lines for both. The error occurs in wmContactUtils.InsertContact, at line 457:
B4X:
Dim rawUri As Uri = cr.Insert(rawContactUri, values)
Any hints would be greatly appreciated as I'm clueless... The attached test project contains one external library: Clipboard, to copy the StackTrace to the clipboard. This library can be found at https://www.b4x.com/android/forum/threads/clipboard-library.7382/

Thanks in advance!
 

Attachments

  • ContactsError.zip
    26.4 KB · Views: 42
Top