cordova-plugin-contacts icon indicating copy to clipboard operation
cordova-plugin-contacts copied to clipboard

App crashed

Open basitraza339 opened this issue 4 years ago • 3 comments

This plugin crashed app android version 8 but contact is save correctly.

basitraza339 avatar Jul 17 '20 19:07 basitraza339

Any Solution on it

abhaysofttech avatar Aug 12 '20 08:08 abhaysofttech

This plugin has broken due to a change in the way Android handles permissions in 8.0 (https://developer.android.com/about/versions/oreo/android-8.0-changes#o-pri).

Basically: in the past requesting the contact write permission would also give you the contact read permission, but now you have to request both if you want to do both (but it will only ask the user once). The reason the save function was crashing the app was because it was writing the contact and then trying to read it back when it only had the write permission.

I've forked the repository and updated the ContactManager.java file to work with Android 8.0: https://github.com/duncan-c/cordova-plugin-contacts/blob/master/src/android/ContactManager.java

You can simply overwrite your ContactManager.java file in the plugins/cordova-plugin-contacts/src/android directory and then force ionic to recompile the plugin by removing and then re-adding the android platform:

ionic platform rm android ionic platform add android

basitraza339 avatar Aug 12 '20 10:08 basitraza339

like @basitraza339 said it's read permission issue on new android version so i used this plugin cordova-plugin-android-permissions to ask first for read permission then save the contanct

permissions.requestPermission(permissions.READ_CONTACTS,() => {

     let contact = navigator.contacts.create();

     contact.displayName = 'Ali'

    contact.save( console.log('contact has been saved successfully '), console.log('contact has not been saved '););

},null)

AliMohammad93 avatar Nov 06 '20 12:11 AliMohammad93

We are archiving this repository following Apache Cordova's Deprecation Policy. We will not continue to work on this repository. Therefore all issues and pull requests are being closed. Thanks for your contribution.

timbru31 avatar Jan 09 '23 07:01 timbru31