Ionic app crash after adding use permission to config.xml file

纵然是瞬间 提交于 2020-06-17 09:13:25

问题


By adding MODIFY_AUDIO_SETTINGS permission to config.xml, my app will crash after run.

<edit-config file="AndroidManifest.xml" mode="merge" target="/manifest/uses-permission" xmlns:android="http://schemas.android.com/apk/res/android">
    <uses-permission android:name="android.permission.MODIFY_AUDIO_SETTINGS"/>
</edit-config>

Then run app:

 ionic cordova run android -- device

Also i try for ionic android permission

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

 this.androidPermissions.checkPermission(this.androidPermissions.PERMISSION.CAMERA).then(
  result =>console.log('Haspermission?',result.hasPermission),
  err =>this.androidPermissions.requestPermission(this.androidPermissions.PERMISSION.CAMERA)
);

But no popup show to ask user for permission. And in the end i used cordova permission directly

ionic cordova plugin add cordova-plugin-android-permissions

declare var cordova:any
var permissions = cordova.plugins.permissions;
permissions.requestPermission(permissions.RECORD_AUDIO, successCallback, errorCallback);

i can get permission of camera or record_audio But requestPermission return false for MODIDY_AUDIO_SETTINGS permission.

permissions.requestPermission(permission.MODIDY_AUDIO_SETTINGS, success, error);

function error() {
    resolve(false);
}

function success(status) {
  if (status.hasPermission) {  // <-- status.hasPermission is false here
     resolve(true);
  } else {
    resolve(false);
  }
}

90% solve========================>

after adding permission manually to AndroidManifest.xml. application show popup to ask permisson now. how can i add this permission to confix.xml instead of directly to AndroidManifest.xml? as i said when i add this permission to config.xml. application wont start.

<uses-permission android:name="android.permission.CAMERA" />
<uses-feature android:name="android.hardware.camera" android:required="true" />
<uses-feature android:name="android.hardware.microphone" android:required="true" />
<uses-permission android:name="android.permission.RECORD_AUDIO" />
<uses-permission android:name="android.permission.MODIFY_AUDIO_SETTINGS" />

回答1:


The issue solved by adding permission to < config-file > tag.

inside config.xml:

<platform name="android">
    ....
    <config-file parent="/manifest" target="AndroidManifest.xml" xmlns:android="http://schemas.android.com/apk/res/android">
        <uses-permission android:name="android.permission.CAMERA" />
        <uses-feature android:name="android.hardware.camera" android:required="true" />
        <uses-feature android:name="android.hardware.microphone" android:required="true" />
        <uses-permission android:name="android.permission.RECORD_AUDIO" />
        <uses-permission android:name="android.permission.MODIFY_AUDIO_SETTINGS" />
    </config-file>
    ....
</platform>

unplug/plug again usb device or reset adb server and re run the application

ionic cordova run android --device

and now, application show popup when sending request for permission.



来源:https://stackoverflow.com/questions/60228926/ionic-app-crash-after-adding-use-permission-to-config-xml-file

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