清单文件添加文件读写权限
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.MANAGE_EXTERNAL_STORAGE" />
class FileUtils {
static checkPermission() {
const Build = plus.android.importClass('android.os.Build');
if(Build.VERSION.SDK_INT >= Build.VERSION_CODES.R){
const Environment = plus.android.importClass("android.os.Environment");
return Environment.isExternalStorageManager();
}
return true
}
static applyPermission(fn) {
const Build = plus.android.importClass('android.os.Build');
if(Build.VERSION.SDK_INT >= Build.VERSION_CODES.R){
var Intent = plus.android.importClass("android.content.Intent");
var Settings = plus.android.importClass("android.provider.Settings");
var Uri = plus.android.importClass("android.net.Uri");
var mainActivity = plus.android.runtimeMainActivity();
var intent = new Intent(Settings.ACTION_MANAGE_APP_ALL_FILES_ACCESS_PERMISSION);
var uri = Uri.fromParts("package", mainActivity.getPackageName(), null);
intent.setData(uri);
// intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
mainActivity.startActivity(intent);
}
fn({state:'ok'})
}
}
if(FileUtils.checkPermission()==false){
that.showLoading("请稍等")
FileUtils.applyPermission(res => {
uni.hideLoading()
})
return
}