如何在 Ionic 3 中使用 cordova-plugin-android-permissions? [英] How to use cordova-plugin-android-permissions in Ionic 3?

查看:32
本文介绍了如何在 Ionic 3 中使用 cordova-plugin-android-permissions?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在我的应用程序中使用了几个 cordova 插件,例如相机和图像选择器,它们在所有设备上都运行良好……但问题在于从手机获取这些插件的权限.Android 6 以下版本在安装时要求这些权限,但 Android 6 及以上版本仅在用户第一次在应用程序中使用该插件时(即在运行时)要求这些权限.

I am using a couple of cordova plugins like camera and Image Pickers in my App and they work great on all the Devices… but the problem comes for getting the Permission to these plugins from the phone. Below Android 6 Versions asks for these permissions while installing but Android 6 and above ask for these permissions only when for the first time when the user uses that plugin inside the application(i.e during the Runtime).

我发现 this Ionic 原生插件可以在所有版本的 Android 中处理这些权限但完全不知道如何在我的代码中使用它或在哪里使用它,所以如果有人有任何视频或对此有所了解,请在此处提及.

I found this Ionic native plugin to handle these permissions in all versions of Android But exactly not getting how to use it or where to use it in my code, So If anyone has any Videos or know anything about it then please mention it here.

谢谢,

推荐答案

我想出了如何使用这个原生插件.这是我尝试过的.

I figured it out how to use this native plugin. this is what I tried.

安装了 this ionic 文档中提到的插件

Installed the Plugin as mentioned in this ionic doc

然后在我的 app.component.ts 文件中

then in my app.component.ts file

import { AndroidPermissions } from '@ionic-native/android-permissions';

constructor(platform: Platform, androidPermissions: AndroidPermissions) {
    platform.ready().then(() => {

         androidPermissions.requestPermissions(
           [
             androidPermissions.PERMISSION.CAMERA, 
             androidPermissions.PERMISSION.CALL_PHONE, 
             androidPermissions.PERMISSION.GET_ACCOUNTS, 
             androidPermissions.PERMISSION.READ_EXTERNAL_STORAGE, 
             androidPermissions.PERMISSION.WRITE_EXTERNAL_STORAGE
           ]
         );

    }) 
}

我希望这会对某人有所帮助.谢谢.

I hope this will help someone. Thanks.

这篇关于如何在 Ionic 3 中使用 cordova-plugin-android-permissions?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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