我有这个代码拍照并保存图片在/data/data/...
,但拍照后我得到Image saved to: /media/external/images/media/a_number
。我检查了/data/data/...
目录,没有图片文件
protected void onCreate(Bundle savedInstanceState) {
context = this;
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
File fileUri = new File(context.getFilesDir(), "INSTALLATION.jpg");
Intent intent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
intent.putExtra(MediaStore.EXTRA_OUTPUT, fileUri); // set the image file name
// start the image capture Intent
startActivityForResult(intent, CAPTURE_IMAGE_ACTIVITY_REQUEST_CODE);
//...
}
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
if (requestCode == CAPTURE_IMAGE_ACTIVITY_REQUEST_CODE) {
if (resultCode == RESULT_OK) {
// Image captured and saved to fileUri specified in the Intent
Toast.makeText(this, "Image saved to:n" + data.getData(), Toast.LENGTH_LONG).show();
} else if (resultCode == RESULT_CANCELED) {
// User cancelled the image capture
} else {
// Image capture failed, advise user
}
}
}
第三方相机应用程序无权写入您的内部存储部分。
欢迎您尝试编写支持流API并支持写入内部存储的ContentProvider
,然后为ACTION_IMAGE_CAPTURE
使用content://
Uri
。我没有尝试过,所以我不知道它的工作效果如何,我怀疑许多相机应用程序不会期望content://
Uri
在那里。
否则,您的选项是:
-
给第三方相机应用一个外部存储的位置,然后自己复制文件到内部存储,或者
-
不要使用
ACTION_IMAGE_CAPTURE
,而是使用Camera
和/或camera2
api直接在您的应用程序中拍照