uniapp权限判断
写法如下
// 检查是否有写入外部存储的权限 function writeExternalStoragePermission() { return new Promise((resolve, reject) => { var Manifest = plus.android.importClass("android.Manifest"); var MainActivity = plus.android.runtimeMainActivity(); let WRITE_EXTERNAL_STORAGE = MainActivity.checkSelfPermission(Manifest.permission.WRITE_EXTERNAL_STORAGE); if (WRITE_EXTERNAL_STORAGE != -1) { console.log('有权限'); resolve(true) } else { console.log('没有权限'); resolve(false)
} }); }
调用
let isFile = await writeExternalStoragePermission() //有没有文件权限
if (!isFile) return checkWriteExternalStoragePermission(); //没有权限跳出并去申请权限
参考自:shadow_glory的文章 https://blog.csdn.net/crsitin_spade/article/details/135138709
本文来自博客园,作者:脆,转载请注明原文链接:https://www.cnblogs.com/Wei-notes/p/18493327