App Crashing with 'Permission Denial' reason even after giving permissions
keertipurswani opened this issue · comments
Did you add the simple_permission plugin? and add the request permission code like for instance:
PermissionStatus authorizationMyAppStatus =
await SimplePermissions.requestPermission(Permission.ReadContacts);
prior to call: var myContactVariable = await ContactsService.getContacts();
I didn't call ' await ContactsService.getContacts();' at all. I just added the package and ran my app.
@keertipurswani Is this still an issue? If so, please provide a piece of sample code and the specs of your platform (iOS/Android, what version, real device/emulator, etc.)
I was using contact picker along with this plugin for another case.
This is still an issue for me.
Here it is the debug console output
D/ViewRootImpl@846453c[MainActivity](29650): ViewPostIme pointer 0
D/ViewRootImpl@846453c[MainActivity](29650): ViewPostIme pointer 1
E/AndroidRuntime(29650): FATAL EXCEPTION: AsyncTask #4
E/AndroidRuntime(29650): Process: co.packagename.packagenamemvp, PID: 29650
E/AndroidRuntime(29650): java.lang.RuntimeException: An error occurred while executing doInBackground()
E/AndroidRuntime(29650): at android.os.AsyncTask$3.done(AsyncTask.java:353)
E/AndroidRuntime(29650): at java.util.concurrent.FutureTask.finishCompletion(FutureTask.java:383)
E/AndroidRuntime(29650): at java.util.concurrent.FutureTask.setException(FutureTask.java:252)
E/AndroidRuntime(29650): at java.util.concurrent.FutureTask.run(FutureTask.java:271)
E/AndroidRuntime(29650): at android.os.AsyncTask$SerialExecutor$1.run(AsyncTask.java:245)
E/AndroidRuntime(29650): at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1162)
E/AndroidRuntime(29650): at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:636)
E/AndroidRuntime(29650): at java.lang.Thread.run(Thread.java:764)
E/AndroidRuntime(29650): Caused by: java.lang.SecurityException: Permission Denial: opening provider com.android.providers.contacts.ContactsProvider2 from ProcessRecord{e768167 29650:co.packagename.packagenamemvp/u0a255} (pid=29650, uid=10255) requires android.permission.READ_CONTACTS or android.permission.WRITE_CONTACTS
E/AndroidRuntime(29650): at android.os.Parcel.readException(Parcel.java:1959)
E/AndroidRuntime(29650): at android.os.Parcel.readException(Parcel.java:1905)
E/AndroidRuntime(29650): at android.app.IActivityManager$Stub$Proxy.getContentProvider(IActivityManager.java:5290)
E/AndroidRuntime(29650): at android.app.ActivityThread.acquireProvider(ActivityThread.java:6158)
E/AndroidRuntime(29650): at android.app.ContextImpl$ApplicationContentResolver.acquireUnstableProvider(ContextImpl.java:2559)
E/AndroidRuntime(29650): at android.content.ContentResolver.acquireUnstableProvider(ContentResolver.java:1786)
E/AndroidRuntime(29650): at android.content.ContentResolver.query(ContentResolver.java:744)
E/AndroidRuntime(29650): at android.content.ContentResolver.query(ContentResolver.java:710)
E/AndroidRuntime(29650): at android.content.ContentResolver.query(ContentResolver.java:668)
E/AndroidRuntime(29650): at flutter.plugins.contactsservice.contactsservice.ContactsServicePlugin.getCursor(ContactsServicePlugin.java:152)
E/AndroidRuntime(29650): at flutter.plugins.contactsservice.contactsservice.ContactsServicePlugin.access$000(ContactsServicePlugin.java:34)
E/AndroidRuntime(29650): at flutter.plugins.contactsservice.contactsservice.ContactsServicePlugin$GetContactsTask.doInBackground(ContactsServicePlugin.java:125)
E/AndroidRuntime(29650): at flutter.plugins.contactsservice.contactsservice.ContactsServicePlugin$GetContactsTask.doInBackground(ContactsServicePlugin.java:112)
E/AndroidRuntime(29650): at android.os.AsyncTask$2.call(AsyncTask.java:333)
E/AndroidRuntime(29650): at java.util.concurrent.FutureTask.run(FutureTask.java:266)
E/AndroidRuntime(29650): ... 4 more
D/ViewRootImpl@846453c[MainActivity](29650): MSG_WINDOW_FOCUS_CHANGED 0
I/zygote64(29650): Do partial code cache collection, code=61KB, data=41KB
I/zygote64(29650): After code cache collection, code=61KB, data=41KB
I/zygote64(29650): Increasing code cache capacity to 256KB
D/SurfaceView(29650): BG show() Surface(name=Background for - SurfaceView - co.packagename.packagenamemvp/co.packagename.packagenamemvp.MainActivity@700277a@0) io.flutter.view.FlutterView{700277a VFE...... .F...... 0,0-1080,2094}
D/SurfaceView(29650): surfaceDestroyed 1 io.flutter.view.FlutterView{700277a VFE...... .F...... 0,0-1080,2094}
D/SurfaceView(29650): BG destroy() Surface(name=Background for - SurfaceView - co.packagename.packagenamemvp/co.packagename.packagenamemvp.MainActivity@700277a@0) io.flutter.view.FlutterView{700277a VFE...... .F...... 0,0-1080,2094}
D/OpenGLRenderer(29650): eglDestroySurface = 0x710732dc20
D/ViewRootImpl@846453c[MainActivity](29650): Relayout returned: old=[0,0][1080,2220] new=[0,0][1080,2220] result=0x5 surface={valid=false 0} changed=true
D/ViewRootImpl@846453c[MainActivity](29650): dispatchDetachedFromWindow
D/InputEventReceiver(29650): channel 'f3a47f1 co.packagename.packagenamemvp/co.packagename.packagenamemvp.MainActivity (client)' ~ Disposing input event receiver.
D/InputEventReceiver(29650): channel 'f3a47f1 co.packagename.packagenamemvp/co.packagename.packagenamemvp.MainActivity (client)' ~NativeInputEventReceiver.
I/FirebaseAuth(29650): [FirebaseAuth:] Loading module via FirebaseOptions.
I/FirebaseAuth(29650): [FirebaseAuth:] Preparing to create service connection to gms implementation
here it is flutter doctor output
[✓] Flutter (Channel beta, v1.0.0, on Mac OS X 10.13.6 17G4015, locale es-AR)
• Flutter version 1.0.0 at /Users/alfredo/Desktop/flutter
• Framework revision 5391447fae (7 weeks ago), 2018-11-29 19:41:26 -0800
• Engine revision 7375a0f414
• Dart version 2.1.0 (build 2.1.0-dev.9.4 f9ebf21297)
[✓] Android toolchain - develop for Android devices (Android SDK 27.0.3)
• Android SDK at /Users/alfredo/Library/Android/sdk
• Android NDK location not configured (optional; useful for native profiling support)
• Platform android-27, build-tools 27.0.3
• Java binary at: /Applications/Android Studio.app/Contents/jre/jdk/Contents/Home/bin/java
• Java version OpenJDK Runtime Environment (build 1.8.0_152-release-1136-b06)
• All Android licenses accepted.
[✓] iOS toolchain - develop for iOS devices (Xcode 10.1)
• Xcode at /Applications/Xcode.app/Contents/Developer
• Xcode 10.1, Build version 10B61
• ios-deploy 2.0.0
• CocoaPods version 1.6.0.beta.2
[✓] Android Studio (version 3.2)
• Android Studio at /Applications/Android Studio.app/Contents
• Flutter plugin version 30.0.1
• Dart plugin version 181.5656
• Java version OpenJDK Runtime Environment (build 1.8.0_152-release-1136-b06)
[✓] VS Code (version 1.30.2)
• VS Code at /Applications/Visual Studio Code.app/Contents
• Flutter extension version 2.21.1
[✓] Connected device (1 available)
• SM G950F • 988a17444535545450 • android-arm64 • Android 8.0.0 (API 26)
• No issues found!
I am just calling
Iterable<Contact> contacts = await ContactsService.getContacts();
contactList = contacts.toList();
AndroidManifest already has permissions
works like a charm in iOS both simulator and phisical device
@quetool did you explicitly ask for permissions in code as suggested by @Peter-717 above?
@clovisnicolas nop, sorry, didn't read that comment. So I need to install another plugin (simple_permission) in orther to make this one work? Will try, thanks!
Yes, it does seem unconvenient but the idea is that you use a single plugin to manage all user permissions.
If Android decides to handle permissions differently in a future version you have a single plugin to update instead of every single plugin.
@clovisnicolas thanks, I solved it quickly with simple_permission plugin, sorry for bothering with a close issue!
PS: that is one of many reasons I like iOS more than Android :P