今天我要处理一件棘手的事情。
我启动相机并希望将拍摄的图像直接保存到我的内部存储器中,而不是将其移动到其中。
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);
似乎如果我尝试将它们直接保存到内部存储器中,相机会忽略我在拍照后单击“确定”按钮。我认为“内部”URI 有问题,因为如果我使用 Environment.getExternalStorageDirectory()
而不是 getApplicationContext().getFilesDir()
作为 extra_output,一切正常很好,但是之后我必须将文件移动到内部存储中(移动过程对“getApplicationContext().getFilesDir()”工作正常)
当我拍照并按下 ok 按钮以继续使用内部 URI 时,相机不会做任何事情...我无法相信在 Android 中存储如此困难。
有什么想法吗?也许相机只允许将照片保存到外部存储器?
最佳答案
尝试下面的代码
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);
关于java - Android 保存相机图片到本地存储,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15475656/