无需使用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/

相关文章

Android性能优化——之控件的优化 前面讲了图像的优化,接下...
前言 上一篇已经讲了如何实现textView中粗字体效果,里面主要...
最近项目重构,涉及到了数据库和文件下载,发现GreenDao这个...
WebView加载页面的两种方式 一、加载网络页面 加载网络页面,...
给APP全局设置字体主要分为两个方面来介绍 一、给原生界面设...
前言 最近UI大牛出了一版新的效果图,按照IOS的效果做的,页...