Android ACTION_IMAGE_捕获,内置内存中有额外的_输出

Android ACTION_IMAGE_捕获,内置内存中有额外的_输出,android,camera,android-sdcard,Android,Camera,Android Sdcard,当我在打电话时用照相机拍照 File file = new File(getFilesDir().getAbsolutePath() + "/myImage.jpg"); Uri outputFileUri = Uri.fromFile(file); cameraIntent = new Intent(android.provider.MediaStore.ACTION_IMAGE_CAPTURE); cameraIntent.putExtra(MediaStore.EXTRA_OUTPUT,

当我在打电话时用照相机拍照

File file = new File(getFilesDir().getAbsolutePath() + "/myImage.jpg");
Uri outputFileUri = Uri.fromFile(file);

cameraIntent = new Intent(android.provider.MediaStore.ACTION_IMAGE_CAPTURE);
cameraIntent.putExtra(MediaStore.EXTRA_OUTPUT, outputFileUri);
OK按钮
摄像头应用程序不起作用,只是什么都不做(实际上不会将其保存到我提供的内存中,因此应用程序本身什么都不做)

如果我打电话

File file = new File(Environment.getExternalStorageDirectory().getAbsolutePath() + "/myImage.jpg");
Uri outputFileUri = Uri.fromFile(file);

cameraIntent = new Intent(android.provider.MediaStore.ACTION_IMAGE_CAPTURE);
cameraIntent.putExtra(MediaStore.EXTRA_OUTPUT, outputFileUri);
一切正常,照片存储在SD卡上


我的问题是,有没有一种方法可以在不使用SD卡的情况下以全分辨率存储捕获的照片?

相机活动将无法将文件保存到活动的私有文件目录中,这就是它悄悄失败的原因。您可以将图像从外部存储器移动到onActivityResult中的文件目录中

本机摄像头应用程序无法将图像保存在应用程序的私有内部目录中,因为这些目录仅适用于特定应用程序

相反,您可以创建自定义相机活动,将图像保存到内部目录,或者您需要使用带有外部存储的stock camera应用程序


注意:如果您计划创建自定义相机活动,请确保您的目标至少为2.3及以上。低于该标记的任何内容都很难使用。

您需要添加权限

cameraIntent.setFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION);
这可以使用文件提供程序实现。请参考样品

  public getOutputUri(@NonNull Context pContext) {
    String photo = photo.jpeg;//your file name
    File photoFile = new File(pContext.getFilesDir(), photo);
    Uri lProviderPath = FileProvider.getUriForFile(pContext,
        pContext.getApplicationContext()
            .getPackageName() + ".provider", photoFile);
    return lProviderPath;
  }



  private void capturePhoto() {
      Intent cameraIntent = new Intent(android.provider.MediaStore.ACTION_IMAGE_CAPTURE);
      cameraIntent.putExtra(MediaStore.EXTRA_OUTPUT, getOutputUri(this));
      cameraIntent.setFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION);
      startActivityForResult(cameraIntent, 1);
  }
有关更多详细信息,请参阅以下android文档

这个想法是外部存储不可用(用户拔出SD卡)。我认为要求用户插入SD卡以便拍照是合理的。否则你就有可能填满他们(有限的)内存,也会使访问这些图片变得更加困难。是的,我的目标是2.2及以上。自定义相机活动似乎是唯一的解决方案。谢谢如果你的目标是2.2,我会尽量避免摄像机旋转。在2.3版本之前的设备中旋转摄像头几乎是不可能的,因为存在硬件缺陷和旧软件。(或者在2.3版本之前的设备中不允许旋转)