我目前正在开发一个需要几个"危险"权限的应用程序.因此,我尝试在Android Marshmallow(API级别23)中添加"请求许可",但无法找到如何执行此操作.
如何在我的应用中使用新的权限模型请求权限?
我使用以下命令启动图像选择器意图:
final Intent pickIntent = new Intent(Intent.ACTION_PICK, MediaStore.Images.Media.EXTERNAL_CONTENT_URI);
pickIntent.putExtra(Intent.EXTRA_ALLOW_MULTIPLE, true);
startActivityForResult(intent, PICK_IMAGE);
Run Code Online (Sandbox Code Playgroud)
然后onActivityResult()我得到所有选择的图像的uris,并启动在后台运行的Jobs并上传这些图像(https://github.com/yigit/android-priority-jobqueue)。但是,如果我按后退按钮并退出活动,那么任何未启动的作业都无法在运行时访问选择的图像并引发异常:
java.lang.SecurityException:权限拒绝:未从uid 10123导出的ProcessRecord {...}(pid = 2407,uid = 10117)打开提供程序com.google.android.apps.photos.contentprovider.MediaContentProvider
发生这种情况的原因是,一旦活动完成,权限就会被撤销。根据文档https://developer.android.com/guide/topics/providers/content-provider-basics.html:
这些是对特定内容URI的权限,该权限将持续到接收它们的活动完成为止。
我的问题是,是否有解决方法?喜欢在应用程序级别获得许可?
有哪些替代方案可以解决此问题?一种快速的解决方案似乎是复制所有拾取的图像,然后上传它们,但这似乎是不得已的方法。
android permission-denied android-contentprovider android-permissions
android ×2