Reputation: 16837
I am trying to follow this tutorial to invoke the camera app and ask it to save a picture at the uri passed in the intent.
File image = File.createTempFile("testImage", ".jpg",
getExternalFilesDir(Environment.DIRECTORY_PICTURES));
Uri uri = Uri.fromFile(image);
Intent i = new Intent();
i.setAction(MediaStore.ACTION_IMAGE_CAPTURE);
i.putExtra(MediaStore.EXTRA_OUTPUT, uri);
if (i.resolveActivity(getPackageManager()) != null) {
startActivityForResult(i, 1);
}
The path of the image is :
/storage/emulated/0/Android/data/com.android.test1.app/files/Pictures/testImage-516714791.jpg
I want to ask that how did the camera app have permission to write to this path ? I am testing on Android 4.4, so the path ExternalFilesDir
is not publicly writable.
Upvotes: 1
Views: 595
Reputation: 57163
The reference says:
There is no security enforced with these files. For example, any application holding WRITE_EXTERNAL_STORAGE can write to these files.
Starting in KITKAT, no permissions are required to read or write to the returned path; it's always accessible to the calling app. This only applies to paths generated for package name of the calling application. To access paths belonging to other packages, WRITE_EXTERNAL_STORAGE and/or READ_EXTERNAL_STORAGE are required.
So, system Camera app, or any other app which is granted WRITE_EXTERNAL_STORAGE
permission can write to /storage/emulated/0/Android/data/com.android.test1.app/files/Pictures/
.
Upvotes: 2