Android Question app crashed (using class-contactsutils provides read write access to the stored contacts)

Almog

Active Member
Licensed User
Hi Erel,

I tried to use the library you uploaded: https://www.b4x.com/android/forum/t...ad-write-access-to-the-stored-contacts.30824/

this is my code(activity_create):
B4X:
    If FirstTime Then
        Activity.LoadLayout("MAIN")
        cu.Initialize
    End If

    Dim FindCo As List
    FindCo.Initialize
    FindCo = cu.FindContactsByName("מקסים",False,False)
    For i = 0 To FindCo.Size - 1
        
        Label2.Text = Label2.Text & cu.GetNameFromId(FindCo.Get(i))
        Label2.Text = Label2.Text & CRLF
        
    Next

and when I runned the app on debug mode, the app crashed.

--------- beginning of crash
--------- beginning of main
*** Service (starter) Create ***
** Service (starter) Start **
** Activity (main) Create, isFirst = true **
Error occurred on line: 114 (ContactsUtils)
java.lang.SecurityException: Permission Denial: opening provider com.android.providers.contacts.ContactsProvider2 from ProcessRecord{961a34c 12738:b4a.example/u0a149} (pid=12738, uid=10149) requires android.permission.READ_CONTACTS or android.permission.WRITE_CONTACTS
at android.os.Parcel.readException(Parcel.java:1684)
at android.os.Parcel.readException(Parcel.java:1637)
at android.app.ActivityManagerProxy.getContentProvider(ActivityManagerNative.java:4199)
at android.app.ActivityThread.acquireProvider(ActivityThread.java:5478)
at android.app.ContextImpl$ApplicationContentResolver.acquireUnstableProvider(ContextImpl.java:2239)
at android.content.ContentResolver.acquireUnstableProvider(ContentResolver.java:1520)
at android.content.ContentResolver.query(ContentResolver.java:518)
at android.content.ContentResolver.query(ContentResolver.java:475)
at anywheresoftware.b4a.objects.ContentResolverWrapper.Query(ContentResolverWrapper.java:49)
at b4a.example.contactsutils._findcontactsidfromdata(contactsutils.java:634)
at b4a.example.contactsutils._findcontactsbyname(contactsutils.java:232)
at b4a.example.main._activity_create(main.java:409)
at java.lang.reflect.Method.invoke(Native Method)
at anywheresoftware.b4a.shell.Shell.runMethod(Shell.java:710)
at anywheresoftware.b4a.shell.Shell.raiseEventImpl(Shell.java:342)
at anywheresoftware.b4a.shell.Shell.raiseEvent(Shell.java:249)
at java.lang.reflect.Method.invoke(Native Method)
at anywheresoftware.b4a.ShellBA.raiseEvent2(ShellBA.java:139)
at b4a.example.main.afterFirstLayout(main.java:104)
at b4a.example.main.access$000(main.java:17)
at b4a.example.main$WaitForLayout.run(main.java:82)
at android.os.Handler.handleCallback(Handler.java:751)
at android.os.Handler.dispatchMessage(Handler.java:95)
at android.os.Looper.loop(Looper.java:154)
at android.app.ActivityThread.main(ActivityThread.java:6121)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:889)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:779)
** Activity (main) Resume **

do you know what is the problem(I Checked line 114 and it was exact as in the project file you uploaded)?

Thanks in advance
 
Top