HMS-Core / hms-scan-demo

Sample code for demonstrating Huawei HMS ScanKit capabilities. It illustrates how to help developers quickly build code scanning capabilities.
https://developer.huawei.com/consumer/en/doc/development/HMS-Guides/scan-introduction-4?ha_source=hms1
Apache License 2.0
306 stars 56 forks source link

android 13设备使用默认模式无法打开相册 #75

Open xj999 opened 2 years ago

xj999 commented 2 years ago

设备:oppo PFEM10 系统:Android13 sdk版本 com.huawei.hms:scan:2.7.0.302 compileSdkVersion:33 targetSdkVersion:33 调用代码

checkPermission(object : PermissionSuccessListener {
            override fun onSuccess() {
                val options = HmsScanAnalyzerOptions.Creator()
                    .setHmsScanTypes(HmsScan.QRCODE_SCAN_TYPE, HmsScan.DATAMATRIX_SCAN_TYPE)
                    .create()
                ScanUtil.startScan(requireActivity(), REQUEST_CODE_SCAN_ONE, options)
            }
            override fun onFail() {
            }
        }, Permission.CAMERA,Permission.READ_MEDIA_IMAGES)

可以进行扫码 无法打开相册

经过排查是sdk内的RemoteView类的startPhotoCode方法没有对Android最新的READ_MEDIA_IMAGES权限进行验证,targetSdkVersion>=33的时候应该验证READ_MEDIA_IMAGES权限而不是READ_EXTERNAL_STORAGE权限

 if (!com.huawei.hms.scankit.util.b.a(var1)) {
            int var10001 = Process.myPid();
            int var18 = Process.myUid();
            if (var1.checkPermission("android.permission.READ_EXTERNAL_STORAGE", var10001, var18) != 0) {
                if (VERSION.SDK_INT >= 23) {
                    var1.requestPermissions(new String[]{"android.permission.READ_EXTERNAL_STORAGE"}, 4371);
                }

                return;
            }
        }
xuxiapu commented 2 years ago

@xj999 您好,请先申请READ_EXTERNAL_STORAGE权限再次尝试。 image

这个权限在Android 13上应该还能使用的,测试的几个手机是没问题的,后续等开发适配。