这不是股票摄像头不被时采取的是相机应用的图片保存图片 [英] Images not being saved when picture is taken by camera app that isn't the stock camera

查看:138
本文介绍了这不是股票摄像头不被时采取的是相机应用的图片保存图片的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

目前,我正在试图挽救从手机拍摄到它的画廊图像,但低于只有code的作品,如果我选择的股票相机应用时,选择对话框弹出。每当我选择另一台相机的应用程序(例如,谷歌摄像头),所拍摄的图片不会被保存任何地方。

为了让事情更奇怪的,有时画面确实出现在画廊的指定目录下,但15分钟左右的时间,也是一样,当我使用的股票相机应用为:该图片将被保存在默认相机镜头目录,但需要相当多的展现在其指定的目录下,如果它显示了那里。

  //捕获摄像机的图像将启动相机应用的要求图像捕捉
无效captureImage(){
    //文件URI存储图像。
    =了fileURI getOutputMediaFileUri(MEDIA_TYPE_IMAGE);

    //请求摄像头应用程序捕捉到的图像
    意图captureIntent =新的意图(MediaStore.ACTION_IM​​AGE_CAPTURE);

    captureIntent.putExtra(MediaStore.EXTRA_OUTPUT,了fileURI);

    //启动图像捕获意向
    。getActivity()startActivityForResult(captureIntent,CAMERA_CAPTURE_IMAGE_REQUEST_ code);

}
 

解决方案

原来,我的code的工作毕竟。这些照片被保存在新目录中,但问题是,画廊没有被更新,这就解释了为什么这些照片会随机出现在目录中以后。作为新本,它永远不会发生,我认为我会更新画廊。我只用ES文件浏览器来浏览我的文件后,来到了这个实现。为了解决我的问题,我只是做我的CameraFragment的新方法,将在媒体上的扫描仪调用。我打电话从onActivityResult()。

此方法

下面是新的方法,虽然没有什么真正的新这件事,因为我遇到了其他做题相同的code:

 保护无效mediaScan(){
    getActivity()。sendBroadcast(
            新的意图(Intent.ACTION_MEDIA_SCANNER_SCAN_FILE,
                    Uri.parse(fileUri.toString())));
}
 

我也不需要调用的包管理系统和遍历,可以处理相机的意图,如果我不给使用选择从一个画廊的图片选项的应用程序,所以我要删除所有从我的问题。

I'm currently trying to save images taken from a phone to its gallery, but the code below only works if I choose the stock camera app when the chooser dialog pops up. Whenever I choose another camera app(e.g., the Google camera), the taken picture doesn't get saved any where.

To make things even stranger, sometimes the picture does show up in its designated directory in the gallery, but after 15 mins or so, the same goes for when I use the stock camera app: the picture will get saved in the default camera shots directory, but takes quite a bit to show up in its designated directory, if it shows up there at all.

// Capturing Camera Image will launch camera app request image capture
void captureImage() {
    //file uri to store image.
    fileUri = getOutputMediaFileUri(MEDIA_TYPE_IMAGE);

    // Request camera app to capture image
    Intent captureIntent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);

    captureIntent.putExtra(MediaStore.EXTRA_OUTPUT, fileUri);

    // start the image capture Intent
    getActivity().startActivityForResult(captureIntent, CAMERA_CAPTURE_IMAGE_REQUEST_CODE);

}

解决方案

It turns out my code was working after all. The pictures were being saved in the new directory, but the problem was that the gallery wasn't being updated, which explains why the photos would randomly appear in the directory later on. Being new to this, it never occurred to me that I would have to update the gallery. I only came to this realization after using ES File Explorer to look through my files. To fix my problem, I just made a new method in my CameraFragment that would call on the media scanner. I called this method from onActivityResult().

Here's the new method, though there's nothing really "new" about it since I ran into the same code on other SO questions:

protected void mediaScan() {
    getActivity().sendBroadcast(
            new Intent(Intent.ACTION_MEDIA_SCANNER_SCAN_FILE, 
                    Uri.parse(fileUri.toString())));
}

I also don't need to call the package manager and iterate through the apps that could handle the camera intent if I'm not giving the option to use choose a picture from a gallery, so I'm going to remove all that from my question.

这篇关于这不是股票摄像头不被时采取的是相机应用的图片保存图片的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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