Closed deidyomega closed 5 years ago
Some people seem to have this invalid enveloppe issue which i'm unable to reproduce on my end... Could you run the example and see if you have the same issue ? If so could you check where exactly it crashes ?
Thanks
I can't get your example to run at all. However my example -->
Create a new flutter project, copy/paste my function in, and have it execute on the example btn click, and you'll see the crash. I tried creating the min required for the bug to appear.
Built build\app\outputs\apk\app-debug.apk.
E/AndroidRuntime(21329): FATAL EXCEPTION: AsyncTask #2
E/AndroidRuntime(21329): Process: flutter.plugins.contactsservice.contactsserviceexample, PID: 21329
E/AndroidRuntime(21329): java.lang.RuntimeException: An error occurred while executing doInBackground()
E/AndroidRuntime(21329): at android.os.AsyncTask$3.done(AsyncTask.java:353)
E/AndroidRuntime(21329): at java.util.concurrent.FutureTask.finishCompletion(FutureTask.java:383)
E/AndroidRuntime(21329): at java.util.concurrent.FutureTask.setException(FutureTask.java:252)
E/AndroidRuntime(21329): at java.util.concurrent.FutureTask.run(FutureTask.java:271)
E/AndroidRuntime(21329): at android.os.AsyncTask$SerialExecutor$1.run(AsyncTask.java:245)
E/AndroidRuntime(21329): at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1162)
E/AndroidRuntime(21329): at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:636)
E/AndroidRuntime(21329): at java.lang.Thread.run(Thread.java:764)
E/AndroidRuntime(21329): Caused by: java.lang.SecurityException: Permission Denial: opening provider com.android.providers.contacts.ContactsProvider2 from ProcessRecord{84630f3 21329:flutter.plugins.contactsservice.contactsserviceexample/u0a81} (pid=21329, uid=10081) requires android.permission.READ_CONTACTS or android.permission.WRITE_CONTACTS
E/AndroidRuntime(21329): at android.os.Parcel.readException(Parcel.java:2004)
E/AndroidRuntime(21329): at android.os.Parcel.readException(Parcel.java:1950)
E/AndroidRuntime(21329): at android.app.IActivityManager$Stub$Proxy.getContentProvider(IActivityManager.java:4758)
E/AndroidRuntime(21329): at android.app.ActivityThread.acquireProvider(ActivityThread.java:5836)
E/AndroidRuntime(21329): at android.app.ContextImpl$ApplicationContentResolver.acquireUnstableProvider(ContextImpl.java:2526)
E/AndroidRuntime(21329): at android.content.ContentResolver.acquireUnstableProvider(ContentResolver.java:1780)
E/AndroidRuntime(21329): at android.content.ContentResolver.query(ContentResolver.java:738)
E/AndroidRuntime(21329): at android.content.ContentResolver.query(ContentResolver.java:704)
E/AndroidRuntime(21329): at android.content.ContentResolver.query(ContentResolver.java:662)
E/AndroidRuntime(21329): at flutter.plugins.contactsservice.contactsservice.ContactsServicePlugin.getCursor(ContactsServicePlugin.java:145)
E/AndroidRuntime(21329): at flutter.plugins.contactsservice.contactsservice.ContactsServicePlugin.access$100(ContactsServicePlugin.java:34)
E/AndroidRuntime(21329): at flutter.plugins.contactsservice.contactsservice.ContactsServicePlugin$GetContactsTask.doInBackground(ContactsServicePlugin.java:120)
E/AndroidRuntime(21329): at flutter.plugins.contactsservice.contactsservice.ContactsServicePlugin$GetContactsTask.doInBackground(ContactsServicePlugin.java:115)
E/AndroidRuntime(21329): at android.os.AsyncTask$2.call(AsyncTask.java:333)
E/AndroidRuntime(21329): at java.util.concurrent.FutureTask.run(FutureTask.java:266)
E/AndroidRuntime(21329): ... 4 more
@deidyomega I see "Permission Denial", have you checked if permissions were enabled?
I did check. I literally cloned your repo, cd'd into the directory and ran the app. I checked, your repo's permissions look correct.
Hey, if you'd be willing to join me on a gotomeeting / skype or something, and resolve this, I'd give you 40 bucks. I know it's not a lot, but it might help you see what is the underlying issue.
@deidyomega @clovisnicolas when you've figured out the problem can you post the solution for the rest of us to understand what was done to resolve the issue?
Can you try this plugin https://github.com/Ethras/flutter_simple_permissions And ask for permissions before adding/fetching contacts ?
@lukasgit I had my team abandon flutter as not having a working contact system is blocking, it really needs to be part of core. I'll look at flutter next year and see if they've gotten basic features like contacts working.
So to answer your question, there is no solution. My 9 lines breaks when adding to the default sample app. And there are no alternative libraries that allow you to add contacts.
@deidyomega I really do believe you are missing Contact permissions on your app.
The error you showed here is exactly the one I have when freshly installing the app on my device, before allowing the app to access contacts.
This plugin does not handle permissions, either the user has to set them manually or use a 3rd party plugin such as https://github.com/Ethras/flutter_simple_permissions
As @clovisnicolas mention, you should handle Permission.WriteContacts permission before adding a new contact, using flutter_simple_permissions plugin:
bool isPermissionGranted = await SimplePermissions.checkPermission(Permission.WriteContacts);
See @clovisnicolas and @bfproject comments above. Closing this issue.
Your add contact example is one line, with no guide on how to initialize the contact.
Looking at the source, I think my below code should work, but it fails with below error. Any idea on how I'm doing wrong?
(Tried on Android 9 && Android 8)
Code:
Error: