现象:apk使用系统定制的静默安装接口安装后没有文件读写权限,但是用adb或其他方式安装该apk却有读写权限
分析:通过adb shell appops get app包名 获取该应用的权限情况
READ_EXTERNAL_STORAGE: allow; rejectTime=+39m55s806ms ago
WRITE_EXTERNAL_STORAGE: allow; rejectTime=+39m55s749ms ago
RUN_IN_BACKGROUND: allow; time=+10m20s420ms ago
CHANGE_WIFI_STATE: allow; time=+11m21s298ms ago
START_FOREGROUND: allow; time=+10m6s324ms ago; duration=+5ms
WRITE_MEDIA_VIDEO: deny; rejectTime=+39m53s988ms ago
WRITE_MEDIA_IMAGES: deny; rejectTime=+39m53s990ms ago
MANAGE_EXTERNAL_STORAGE: default; rejectTime=+39m55s805ms ago
USE_ICC_AUTH_WITH_DEVICE_IDENTIFIER: default; rejectTime=+10m17s645ms ago
对比发现MANAGE_EXTERNAL_STORAGE 是default,并且被reject,而且reject时间在READ_EXTERNAL_STORAGE、WRITE_EXTERNAL_STORAGE附件,猜想可能跟这个有关,
百度了一下,android11的存储策略有改动
解决方法
除了声明获取 MANAGE_EXTERNAL_STORAGE ,WRITE_EXTERNAL_STORAGE权限,还要再获取MANAGE_EXTERNAL_STORAGE权限,拥有更大范围的文件访问权限