Skip to content Skip to sidebar Skip to footer

Custom Uses-permission With Ionic 3

On app builds with Ionic3 (cordova 7.0.0 | android@6.2.3), I need to use microphone, SIP and internet access (WI-FI). So I try edit config.xml with edit-config in this way:

Solution 1:

To add those permissions you need to use <config-file> not <edit-config>, for example:

    <config-file parent="/*" target="AndroidManifest.xml">
        <uses-permission android:name="android.permission.USE_SIP" />
        <uses-permission android:name="android.permission.RECORD_AUDIO" />
        <uses-permission android:name="android.permission.MODIFY_AUDIO_SETTINGS" />
        <uses-permission android:name="android.webkit.PermissionRequest" />
        <uses-feature android:name="android.hardware.sip.voip" />
        <uses-feature android:name="android.hardware.wifi" android:required="true" />
        <uses-feature android:name="android.hardware.microphone" android:required="true" />
    </config-file>

But that's not enough on Android 6+ - you need to request runtime permission for dangerous permissions.

In Cordova you could do this using cordova-diagnostic-plugin with requestRuntimePermissions(), e.g.:

cordova.plugins.diagnostic.requestRuntimePermissions(function(statuses){
    for (var permission in statuses){
        switch(statuses[permission]){
            case cordova.plugins.diagnostic.permissionStatus.GRANTED:
                console.log("Permission granted to use "+permission);
                break;
            case cordova.plugins.diagnostic.permissionStatus.NOT_REQUESTED:
                console.log("Permission to use "+permission+" has not been requested yet");
                break;
            case cordova.plugins.diagnostic.permissionStatus.DENIED:
                console.log("Permission denied to use "+permission+" - ask again?");
                break;
            case cordova.plugins.diagnostic.permissionStatus.DENIED_ALWAYS:
                console.log("Permission permanently denied to use "+permission+" - guess we won't be using it then!");
                break;
        }
    }
}, function(error){
    console.error("The following error occurred: "+error);
},[
    cordova.plugins.diagnostic.permission.USE_SIP,
    cordova.plugins.diagnostic.permission.RECORD_AUDIO
]);

Post a Comment for "Custom Uses-permission With Ionic 3"