相关疑难解决方法(0)

使用Cache Uri作为MediaStore.EXTRA_OUTPUT时,相机无法正常工作/保存

我试图从拍摄照片后获得完整的图像Fragment.

如果我使用文件(Uri.fromFile(file))中的Uri,拍摄照片并点击"确定"按钮后相机将不会退出(看起来无法写入Uri或谁知道什么).

使用File String,形式'/data/data/com.package.bla/cache/img198346262jpg',它不能正常工作(文件在那里,但它是空的,因为相机没有保存任何东西).

到目前为止我尝试了什么:

  • 创建文件后删除文件,如本例所示.但是,相机退出后文件不存在.
  • 添加外部存储READ权限,以防万一

所以我不知道为什么图像没有被保存,并且已经花费/浪费了大量时间测试并弄清楚它为什么不起作用.

分段:

private void launchCamera() {
    Intent cameraIntent = new Intent(android.provider.MediaStore.ACTION_IMAGE_CAPTURE);
    File outputDir = getActivity().getCacheDir();
    File file = null;
    try {
        file = File.createTempFile("img", "jpg", outputDir);
    } catch (IOException e) {
        e.printStackTrace();
    }
    if (file != null) {
        mImageUri = Uri.fromFile(file);   //using Uri is not even exiting the camera
        //mImageUri = File.toString();    //If I use String instead of an Uri, it works better …
Run Code Online (Sandbox Code Playgroud)

android android-intent android-camera

21
推荐指数
2
解决办法
1万
查看次数

标签 统计

android ×1

android-camera ×1

android-intent ×1