未经许可使用Android 6.0捕获图像 [英] Capture image without permission with Android 6.0

查看:111
本文介绍了未经许可使用Android 6.0捕获图像的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要让用户使用Android 6.0拍照(从图库或相机应用程序中).

I need to let the user take a picture (from the gallery or from a camera app) with Android 6.0.

因为我不需要控制相机,所以我想使用这里描述的意图:

Because I don't need to control the camera, I wanted to use an intent as describe here:

但是,如果不需要这种控制,则可以使用ACTION_IMAGE_CAPTURE意图请求图像.启动意图时,系统会提示用户选择一个相机应用程序(如果还没有默认的相机应用程序),然后该应用程序将拍照.相机应用将图片返回到应用的onActivityResult()方法.

However, if you don't need such control, you can just use an ACTION_IMAGE_CAPTURE intent to request an image. When you start the intent, the user is prompted to choose a camera app (if there isn't already a default camera app), and that app takes the picture. The camera app returns the picture to your app's onActivityResult() method.

https://developer.android.com/preview/features/runtime-permissions.html

但是对于此 ACTION_IMAGE_CAPTURE ,您需要填充额外的"MediaStore.EXTRA_OUTPUT" ,这是临时文件的Uri(没有此参数,我将只有一个缩略图).此临时文件必须位于外部存储中(可通过相机应用访问).您需要权限 WRITE_EXTERNAL_STORAGE 才能在外部存储设备上创建文件.

But for this ACTION_IMAGE_CAPTURE, you need to fill the extra "MediaStore.EXTRA_OUTPUT" which is an Uri to a temp file (without this param I will have only a thumbnail). This temp file must be into the external storage (to be accessible by the camera app). You need the permission WRITE_EXTERNAL_STORAGE to create a file on the external storage.

因此,没有 permission android.permission.CAMERA android.permission.WRITE_EXTERNAL_STORAGE 的本地对话框/应用程序无法捕获图像.正确吗?

So it's not possible to capture an image through native dialogs/apps without the permission android.permission.CAMERA or android.permission.WRITE_EXTERNAL_STORAGE. Is that correct?

谢谢

推荐答案

如果您在android 4.4+上,可以将MediaStore.EXTRA_OUTPUT指定为 package-specific下的文件 目录

It is possible if you on android 4.4+, you can specify MediaStore.EXTRA_OUTPUT, to be a file under your package-specific directories

从Android 4.4开始,文件的所有者,组和模式 外部存储设备现在基于目录进行合成 结构体.这使应用程序可以管理其程序包特定的 外部存储中的目录,而无需占用大量存储空间 WRITE_EXTERNAL_STORAGE权限. 例如,带有软件包的应用 名称com.example.foo现在可以自由访问 外部存储设备上的Android/data/com.example.foo/,没有 权限.这些综合权限是通过以下方式完成的: 将原始存储设备包装在FUSE守护程序中.

Starting in Android 4.4, the owner, group and modes of files on external storage devices are now synthesized based on directory structure. This enables apps to manage their package-specific directories on external storage without requiring they hold the broad WRITE_EXTERNAL_STORAGE permission. For example, the app with package name com.example.foo can now freely access Android/data/com.example.foo/ on external storage devices with no permissions. These synthesized permissions are accomplished by wrapping raw storage devices in a FUSE daemon.

https://source.android.com/devices/storage/

这篇关于未经许可使用Android 6.0捕获图像的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆