Reputation: 31739
I have this code to take a picture and save the picture in /data/data/...
, but after taking the picture I get Image saved to: /media/external/images/media/a_number
. I have checked the /data/data/...
directory and the picture file is not there.
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
}
}
}
Upvotes: 0
Views: 55
Reputation: 1007399
Third-party camera apps have no rights to write to your portion of internal storage.
You are welcome to try writing a ContentProvider
that supports the streaming API and supports writing to your internal storage, then use a content://
Uri
for ACTION_IMAGE_CAPTURE
. I haven't tried this, so I don't know how well it works, and I suspect many camera apps won't expect a content://
Uri
there.
Otherwise, your options are:
Give the third-party camera app a location on external storage, then copy the file yourself to internal storage, or
Do not use ACTION_IMAGE_CAPTURE
, but instead use the Camera
and/or camera2
APIs to take a picture directly in your app
Upvotes: 1