相机意图/活动 - 避免保存到相册意图、相机、相册

2023-09-06 13:51:49 作者:壮志凌云

我现在用的是摄像头活动捕捉的画面。我把它用在 MediaStore.EXTRA_OUTPUT 额外的参数。图像被正确地保存到提供的路径,把它也保存到库文件夹,这样我就可以查看画廊应用程序中的形象 - 我能避免这种

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 );
...

感谢

推荐答案

只需更换您的code

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

与下面code

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

描述getExternalFilesDir()的: 返回的绝对路径的主要外部文件系统的目录(即在 Environment.getExternalStorageDirectory某处()),其中的应用程序可以将它拥有持久的文件。这些文件是内部的应用程序,而不是典型地对用户可见的介质。

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.