|
|
@@ -1,6 +1,6 @@
|
|
|
/* eslint-disable */
|
|
|
import { v4 } from 'uuid'
|
|
|
-import { SystemInfo, ShareMessage, HttpRequestConfig, Download } from './types'
|
|
|
+import { SystemInfo, ShareMessage, HttpRequestConfig, Download,AndroidPermissions } from './types'
|
|
|
import { urlScheme } from './constants'
|
|
|
|
|
|
declare global {
|
|
|
@@ -518,12 +518,46 @@ export default new (class {
|
|
|
* 检查运行环境的权限
|
|
|
* https://www.html5plus.org/doc/zh_cn/navigator.html#plus.navigator.checkPermission
|
|
|
*/
|
|
|
- checkPermission() {
|
|
|
- this.onPlusReady((plus) => {
|
|
|
- const res = plus.navigator.checkPermission('READ_EXTERNAL_STORAGE')
|
|
|
+ checkPermission(permissions: keyof typeof AndroidPermissions) {
|
|
|
+ if (this.hasPlus() && this.getSystemInfo('os') === 'Android') {
|
|
|
+ this.onPlusReady((plus) => {
|
|
|
+ const [majorVersion] = plus.os.version.split('.') // 获取系统主版本号
|
|
|
+
|
|
|
+ // 检查相册权限
|
|
|
+ const checkImagesPermission = () => {
|
|
|
+ switch (true) {
|
|
|
+ case (+majorVersion <= 12):
|
|
|
+ return plus.navigator.checkPermission('android.permission.READ_EXTERNAL_STORAGE')
|
|
|
+ case (+majorVersion === 13):
|
|
|
+ return plus.navigator.checkPermission('android.permission.READ_MEDIA_IMAGES')
|
|
|
+ default:
|
|
|
+ return plus.navigator.checkPermission('android.permission.READ_MEDIA_VISUAL_USER_SELECTED')
|
|
|
+ }
|
|
|
+ }
|
|
|
|
|
|
- console.log(res)
|
|
|
- })
|
|
|
+ // 检查视频权限
|
|
|
+ const checkVideoPermission = () => {
|
|
|
+ switch (true) {
|
|
|
+ case (+majorVersion <= 12):
|
|
|
+ return plus.navigator.checkPermission('android.permission.READ_EXTERNAL_STORAGE')
|
|
|
+ case (+majorVersion === 13):
|
|
|
+ return plus.navigator.checkPermission('android.permission.READ_MEDIA_VIDEO')
|
|
|
+ default:
|
|
|
+ return plus.navigator.checkPermission('android.permission.READ_MEDIA_VISUAL_USER_SELECTED')
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ switch (permissions) {
|
|
|
+ case 'IMAGES':
|
|
|
+ return checkImagesPermission()
|
|
|
+ case 'VIDEO':
|
|
|
+ return checkVideoPermission()
|
|
|
+ default:
|
|
|
+ return 'unknown'
|
|
|
+ }
|
|
|
+ })
|
|
|
+ }
|
|
|
+ return 'authorized'
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
@@ -563,8 +597,9 @@ export default new (class {
|
|
|
*/
|
|
|
requestPermissionReadExternalStorage(options: Partial<{ onSuccess: () => void; onError: (message: string) => void; }> = {}) {
|
|
|
// https://ask.dcloud.net.cn/question/190261
|
|
|
+ // https://developer.android.google.cn/about/versions/14/changes/partial-photo-video-access?hl=zh-cn
|
|
|
this.requestPermission({
|
|
|
- permissions: ['android.permission.READ_EXTERNAL_STORAGE', 'android.permission.READ_MEDIA_IMAGES'],
|
|
|
+ permissions: ['android.permission.READ_EXTERNAL_STORAGE', 'android.permission.READ_MEDIA_IMAGES', 'android.permission.READ_MEDIA_VISUAL_USER_SELECTED'],
|
|
|
errorMessage: '请打开存储权限',
|
|
|
refuseMessage: '访问存储被拒绝',
|
|
|
onSuccess: options.onSuccess,
|