Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to use cordova-plugin-android-permissions in Ionic 3?

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).

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.

Thanks,

like image 411
SjVnyk Avatar asked Dec 07 '22 16:12

SjVnyk


1 Answers

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

Installed the Plugin as mentioned in this ionic doc

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.

like image 164
SjVnyk Avatar answered Jan 13 '23 16:01

SjVnyk