为什么在尝试在Android 8上保存联系人时,ionic-native/contacts插件会使应用程序崩溃? [英] Why ionic-native/contacts plugin crash the app when try to save contact at android 8?

查看:117
本文介绍了为什么在尝试在Android 8上保存联系人时,ionic-native/contacts插件会使应用程序崩溃?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我尝试使用ionic-native/contacts plugin保存联系人,它适用于除android 8之外的所有android版本,该应用已停止并关闭. 这是我的代码,与离子框架示例相同:

I try to save contact using ionic-native/contacts plugin, it works on all android versions except android 8, the app is stopped and closed. This is my code which is the same of ionic framework example:

SaveToContact(phone, name) {
try {

  let contact: Contact = this.contacts.create();
  contact.name = new ContactName(null, name, '');
  contact.phoneNumbers = [new ContactField('mobile', phone)];
  this.global.presentToast('Will Save!'),
    contact.save().then(
      () => this.global.presentToast('Contact saved!'),
      (error: any) => this.global.presentToast('Error saving contact: No Permission')
    );
} catch (e) {
  this.global.presentToast(e);
}

我使用android-26来构建apk,而这些是ionic-native/contacts plugin

I used android-26 to build apk, and these are the versions for ionic-native/contacts plugin

"@ angular/core":"5.0.3"

"@angular/core": "5.0.3"

离子角":"3.9.2"

"ionic-angular": "3.9.2"

"cordova-plugin-contacts":"^ 3.0.1"

"cordova-plugin-contacts": "^3.0.1"

"@ ionic-native/contacts":"^ 4.7.0"

"@ionic-native/contacts": "^4.7.0"

我也将插件对象放在应用程序模块的provider数组中,但仍然使应用程序崩溃.

I also put the plugin object in the provider array in the app module, but still the app crash.

推荐答案

此插件已损坏,原因是Android处理8.0中权限的方式发生了变化( https://developer.android.com/about/versions/oreo/android-8.0-changes#o-pri ).

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.

我已分叉存储库并更新了ContactManager.java文件以使其可用于Android 8.0:

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

您可以简单地覆盖 plugins/cordova-plugin-contacts/src/android 目录中的ContactManager.java文件,然后通过删除然后重新添加android来强制ionic重新编译插件.平台:

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

这篇关于为什么在尝试在Android 8上保存联系人时,ionic-native/contacts插件会使应用程序崩溃?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆