Camera intent/Activity - avoid saving to gallery

…衆ロ難τιáo~ 提交于 2019-12-04 10:37:01

问题


I am using the Camera Activity to capture the picture. I call it with the MediaStore.EXTRA_OUTPUT extra parameter. The image is correctly saved to provided path, put it is saved also to the gallery folder, so I can view the image in "Gallery" application - can I avoid this?

...
File file = new File(Environment.getExternalStorageDirectory(), "Test.jpg" );
iImageOutputUri = Uri.fromFile( file );

// Start camera intent to capture image
Intent intent = new Intent( MediaStore.ACTION_IMAGE_CAPTURE );
intent.putExtra( MediaStore.EXTRA_OUTPUT, iImageOutputUri );
startActivityForResult( intent, CAPTURE_IMAGE );
...

Thanks


回答1:


Just replace your code

File file = new File(Environment.getExternalStorageDirectory(), "Test.jpg" );

with following code

File file = new File(getExternalFilesDir(Environment.DIRECTORY_PICTURES), "Test.jpg");

Description of getExternalFilesDir() : Returns the absolute path to the directory on the primary external filesystem (that is somewhere on Environment.getExternalStorageDirectory()) where the application can place persistent files it owns. These files are internal to the applications, and not typically visible to the user as media.




回答2:


How about saving your images with non-image extension ? Something like michael.photo instead of michael.jpg/png etc.That way Gallery app wont take them in and I have seen many such apps keepsafe for example does this.




回答3:


I don't believe you can avoid this. The gallery application looks through your SD card for images and displays them automatically.



来源:https://stackoverflow.com/questions/5221704/camera-intent-activity-avoid-saving-to-gallery

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!