ionic 在Android8.0以上会出现相机打不开,下载apk打不开的情况,为了解决以上问题,具体方案如下
1 插件 cordova-plugin-android-permissions 1.0.0
安装插件 cordova pluign add cordova-plugin-android-permissions
2 相关的拍照权限
```
function checkPermissions() {
const permissions = cordova.plugins.permissions,
permissionList = [permissions.CAMERA,
permissions.WRITE_EXTERNAL_STORAGE,
permissions.INSTALL_LOCATION_PROVIDER];
function errorCallbacks() {
console.warn("permissions is not turned on");
}
function checkPermissionCallbacks(status) {
if(!status.hasPermission) {
permissions.requestPermissions(
permissionList,
status => {
if(!status.hasPermission) errorCallbacks();
},
errorCallbacks);
}
}
permissions.hasPermission(permissionList, checkPermissionCallbacks, null);
}
checkPermissions()
```
3 相关apk下载权限
```
function userDate(url, targetPath){
var permissions = cordova.plugins.permissions;
permissions.hasPermission(permissions.READ_EXTERNAL_STORAGE,checkPermissionCallback, null);
function checkPermissionCallback(status) {
if (!status.hasPermission) {
var errorCallback = function(){
console.log('Storagepermission is not turned on');
}
permissions.requestPermission(
permissions.READ_EXTERNAL_STORAGE,
function(status) {
if(!status.hasPermission) {
errorCallback();
} else {
// download_app();
download_app(url,targetPath)
}
},
errorCallback);
}else{
download_app(url, targetPath)
}
}
}
```
注:bug
a. 安装插件之后,对应的ionic1版本的话,安装之后会造成不能打包,需要在安装插件时 file插件对应版本号安装,添加Android平台时需要cordova platform add android@6.3.0,
此时需要查看平台是否添加完整。
b. 为了解决权限问题,添加权限之后需要在AndroidMifeat
固定版本号
<uses-sdk android:minSdkVersion="16" android:targetSdkVersion="26"/>
权限查看
```
<uses-permission android:name="android.permission.INTERNET"/>
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE"/>
<uses-permission android:name="android.permission.ACCESS_WIFI_STATE"/>
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/>
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE"/>
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION"/>
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION"/>
<uses-permission android:name="android.permission.CHANGE_WIFI_STATE"/>
<uses-permission android:name="android.permission.READ_PHONE_STATE"/>
<uses-permission android:name="android.permission.MOUNT_UNMOUNT_FILESYSTEMS"/>
<uses-permission android:name="android.permission.RECEIVE_USER_PRESENT"/>
<uses-permission android:name="android.permission.WAKE_LOCK"/>
<uses-permission android:name="android.permission.WRITE_SETTINGS"/>
<uses-permission android:name="android.permission.VIBRATE"/>
<uses-permission android:name="android.permission.INSTALL_LOCATION_PROVIDER"/>
<uses-permission android:name="android.permission.REQUEST_INSTALL_PACKAGES"/>
```
c. 如果build时遇到transform…错 在Android平台下build.gradle
configurations.all {
resolutionStrategy {
force 'com.android.support:support-v4:27.1.0'
}
}
def promptForReleaseKeyPassword()之前添加
网友评论