无需使用Android 6.0即可捕获图像

前端之家收集整理的这篇文章主要介绍了无需使用Android 6.0即可捕获图像前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
我需要让用户使用 Android 6.0拍摄照片(从画廊或相机应用程序).

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

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,您需要将一个Uri的额外的“MediaStore.EXTRA_OUTPUT”填入一个临时文件(没有这个参数,我将只有一个缩略图).此临时文件必须进入外部存储(可由相机应用程序访问).您需要获得WRITE_EXTERNAL_STORAGE权限才能在外部存储上创建一个文件.

所以没有权限的android.permission.CAMERA或android.permission.WRITE_EXTERNAL_STORAGE无法通过本机对话框/应用程序捕获图像.那是对的吗?

谢谢

解决方法

这是可能的,如果你在android 4.4,你可以指定MediaStore.EXTRA_OUTPUT,成为你的包特定的文件
目录

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/

原文链接:https://www.f2er.com/android/309819.html

猜你在找的Android相关文章