Android将相机图片保存到本地存储

Nik*_*iko 5 java storage camera android internal

今天我必须处理一件困难的事情.

我启动相机并希望将拍摄的图像直接保存到我的内部存储器中,而不是将其移入其中.

    File targetDir = new File(getApplicationContext().getFilesDir()+File.separator+"PROJECTMAIN"+File.separator+"SUBFORDER");
    targetDir.mkdirs(); //create the folder if they don't exist

    File externalFile = new File(targetDir, "picturename.jpg");
    Uri imageURI = Uri.fromFile(externalFile);

    Intent takePictureIntent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
    takePictureIntent.putExtra(MediaStore.EXTRA_OUTPUT, imageURI);
    startActivityForResult(takePictureIntent, actionCode);
Run Code Online (Sandbox Code Playgroud)

似乎如果我尝试将它们直接保存到内部存储器中,相机会在我拍照后忽略我对"确定"按钮的点击.我认为"内部"URI存在问题,因为如果我使用Environment.getExternalStorageDirectory()而不是getApplicationContext().getFilesDir()extra_output,一切正常,但之后我必须将文件移动到内部存储中(移动过程正常工作到"getApplicationContext() .getFilesDir()")

当我拍照并按下确定按钮继续使用内部URI时,相机根本不做任何事情......我无法相信在Android中使用存储会有困难.

有任何想法吗?也许相机只允许将图片保存到外部存储?

Aju*_*Aju 3

尝试以下代码

File dir= context.getDir("dirname", Context.MODE_PRIVATE); //Creates Dir inside internal memory
File file= new File(dir, "filename");  //It has directory details and file name
FileOutputStream fos = new FileOutputStream(file);
Run Code Online (Sandbox Code Playgroud)