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

posted @ 2024-10-22 17:16    阅读(27)  评论(0编辑  收藏  举报