从相机专卖店形象为民营应用缓存目录 [英] Store image from camera into private app cache directory

查看:149
本文介绍了从相机专卖店形象为民营应用缓存目录的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想从摄像机捕获图像,并将其保存到专用的应用程序缓存目录。我意识到,我必须给相机应用的权限写信给我的私人目录,所以我增加了 FLAG_GRANT_WRITE_URI_PERMISSION 标记。

I would like to capture an image from the camera and save it to the private app cache directory. I realize that I have to give the camera app permission to write to my private directory, so I added the FLAG_GRANT_WRITE_URI_PERMISSION flag.

这是怎么回事时,相机的应用程序打开时,我可以拍摄照片,但是当我点击确定按钮,没有任何反应。相机应用程序保持打开状态。没有日志输出。我想这是因为权限问题。

What's happening is, that the camera app opens, I can take the picture, but when i click on the OK button, nothing happens. The camera app stays open. No log output. I guess it's because of a permission problem.

private void getCameraImage() {
    try {
        mTmpFile = File.createTempFile("tmp", ".jpg", getCacheDir());
        Uri imgUri = Uri.fromFile(mTmpFile);
        Intent i = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
        i.putExtra(MediaStore.EXTRA_OUTPUT, imgUri);
        i.addFlags(Intent.FLAG_GRANT_WRITE_URI_PERMISSION);
        // i.setData(imgUri); // if uncommented, i get an ActivityNotFound Exception
        startActivityForResult(i, REQUEST_CAMERA);
    } catch (IOException e) {
        Log.e(TAG, "getCameraImage()", e);
        Toast.makeText(this, "Something went wrong", Toast.LENGTH_SHORT).show();
    }
}

任何见解,我怎么能纠正?

Any insights, on how I could correct that?

编辑:

当我更改目录向公众SD卡,然后正常工作。

When I change the directory to the public SD card, then it works fine.

mTmpFile = File.createTempFile("tmp", ".jpg", Environment.getExternalStorageDirectory());

谢谢 西蒙

推荐答案

而不是传递的URI来存储图片,您可以使用http://developer.android.com/reference/android/hardware/Camera.html#takePicture(android.hardware.Camera.ShutterCallback, android.hardware.Camera.PictureCallback,android.hardware.Camera.PictureCallback,android.hardware.Camera.PictureCallback)

Instead of passing the Uri to store the picture you can use http://developer.android.com/reference/android/hardware/Camera.html#takePicture(android.hardware.Camera.ShutterCallback, android.hardware.Camera.PictureCallback, android.hardware.Camera.PictureCallback, android.hardware.Camera.PictureCallback)

和得到您的应用程序的内存内容。从那里,你可以做任何你想要的。

and get the content in your app memory. From there you will be able to do anything you want.

不要忘了,使用也美术馆和画廊的应用程序摄像头应用不允许查看您的私人目录。

Do not forget that camera applications are using also the gallery and the gallery app is not allowed to check your private directory.

这篇关于从相机专卖店形象为民营应用缓存目录的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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