【问题标题】:Camera Intent: Picture missing in gallery相机意图:图库中缺少图片
【发布时间】:2014-08-20 09:50:35
【问题描述】:

我有一个启动相机意图的应用程序,以便用户可以拍照。拍摄照片后,它会保存在特定文件夹的外部存储中。问题是我在画廊里看不到它。你有什么建议吗?我应该在 onActivityResult() 中做些什么吗?如果是,是什么?

这是代码(我使用了 android 文档中的代码):

public void takePicture() {
        Intent takePictureIntent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
        // Ensure that there's a camera activity to handle the intent
        if (takePictureIntent.resolveActivity(getPackageManager()) != null) {
            // Create the File where the photo should go
            File photoFile = null;
            try {
                photoFile = createImageFile();
            } catch (IOException ex) {
                // Error occurred while creating the File
            }
            // Continue only if the File was successfully created
            if (photoFile != null) {
                takePictureIntent.putExtra(MediaStore.EXTRA_OUTPUT,
                        Uri.fromFile(photoFile));
                startActivityForResult(takePictureIntent, REQUEST_TAKE_PHOTO);
            }
        }
    }

@SuppressLint("SimpleDateFormat")
private File createImageFile() throws IOException {
    // Create an image file name
    String timeStamp = new SimpleDateFormat("yyyyMMdd_HHmmss")
            .format(new Date());
    String imageFileName = "IMG_" + timeStamp + "_";

    File imageFile = new File(Environment.getExternalStorageDirectory()
            + "/LocalSin");

    if (!imageFile.exists()) {
        imageFile.mkdirs();
    }

    File image = File.createTempFile(imageFileName, ".jpg", imageFile);

    // Save a file: path for use with ACTION_VIEW intents
    mCurrentPhotoPath = "file:" + image.getAbsolutePath();
    return image;
}

【问题讨论】:

    标签: android android-camera android-gallery android-camera-intent


    【解决方案1】:

    拍照后使用此代码。

    public void addPicInGalery()
    {
        Intent scan= new Intent(Intent.ACTION_MEDIA_SCANNER_SCAN_FILE);
        File file=new File(path); // destination path where u want to store image
        Uri uri=Uri.fromFile(file);
        scan.setData(uri);
        getActivity().sendBroadcast(scan);
    }
    

    【讨论】:

      猜你喜欢
      • 2018-08-27
      • 1970-01-01
      • 1970-01-01
      • 2012-03-30
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2011-12-04
      相关资源
      最近更新 更多