【问题标题】:Android Camera intent with Uri not saving the images on Camera folder带有 Uri 的 Android 相机意图未将图像保存在相机文件夹中
【发布时间】:2014-07-14 12:09:12
【问题描述】:

我正在使用Camera Intent 和以下代码

    public void clickPicturesThroughCamera() {
    try {
        Intent intent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
        initImageUri();
        intent.putExtra(MediaStore.EXTRA_OUTPUT, imageUri);
        startActivityForResult(intent, RETURN_FROM_CAMERA);
    } catch (Exception e) {
        showToast(getString(R.string.error_opening_camera));
    }
 }


    public void initImageUri() {
    ContentValues cv = new ContentValues();
    SimpleDateFormat simpleDateFormat = new SimpleDateFormat(dateFormat,
            Locale.ENGLISH);
    String name =simpleDateFormat.format(Calendar.getInstance().getTime())
            + "_" + new Random().nextInt(100) + ".jpg";
    cv.put(MediaStore.Images.Media.TITLE, name);
    imageUri = getContentResolver().insert(
            MediaStore.Images.Media.EXTERNAL_CONTENT_URI, cv);

}

捕获的图像将存储在/storage/sdcard0/DCIM/Camera/imagename.jpg。但是当我通过默认的相机应用程序单击图像时,它将存储在storage/extSdCard/DCIM/Camera/imagename.jpg,因为我默认使用外部 sdcard 来存储捕获的图像。

所以我的主要要求是我正在开发的应用程序应该将捕获的图像存储在默认位置,即storage/extSdCard/DCIM/Camera/imagename.jpg而不是/storage/sdcard0/DCIM/Camera/imagename.jpg。为此,我应该在上面的代码中做什么,以便它始终将图像保存在默认的 Camera 文件夹中。

谢谢

【问题讨论】:

    标签: android android-camera-intent


    【解决方案1】:

    路径可能因设备而异。通过使用 MediaStore.Images.Media.EXTERNAL_CONTENT_URI,您正在向设备询问正确的路径。

    http://developer.android.com/reference/android/provider/MediaStore.Images.Media.html

    【讨论】:

      猜你喜欢
      • 2012-12-07
      • 1970-01-01
      • 2019-12-12
      • 1970-01-01
      • 2012-12-20
      • 1970-01-01
      • 2011-11-08
      • 1970-01-01
      相关资源
      最近更新 更多