Custom uses-permission with ionic 3

半城伤御伤魂 提交于 2019-12-25 01:01:25

问题


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:

<edit-config file="AndroidManifest.xml" mode="merge" targe="/manifest”>
<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" />
</edit-config>

but no request is shown. Moreover, I wish that AndroidManifest.xml has more uses-permission keys (one for every request) but the result is one row with only permission for RECORD_AUDIO.

What am I doing wrong?

Thanks in advice for the answers.


回答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
]);


来源:https://stackoverflow.com/questions/54674872/custom-uses-permission-with-ionic-3

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!