[英]How to create separate private folder for captured images?
I am trying to create a separate folder for captured images using the code and below code is working fine for creating separate folder and images also saved in that folder 我正在尝试使用该代码为捕获的图像创建一个单独的文件夹,下面的代码对于创建单独的文件夹以及也保存在该文件夹中的图像来说效果很好
My problem is captured images also appear in gallery and I don't want to show them in my gallery , Can someone help me please what will I do for my requirement 我的问题是拍摄的图像也出现在画廊 ,我不想让他们在我的画廊 ,有人可以帮我什么我就为我的要求做
ContentValues values = new ContentValues();
values.put(MediaStore.Images.Media.TITLE, "New Picture");
values.put(MediaStore.Images.Media.DESCRIPTION, "From your Camera");
imageUri = getContentResolver().insert(
MediaStore.Images.Media.EXTERNAL_CONTENT_URI, values);
Intent intent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
intent.putExtra(MediaStore.EXTRA_OUTPUT, imageUri);
startActivityForResult(intent, Constants.CAMERA_REQUEST_CODE);
private void onCaptureImageResult(Intent data) {
Bitmap bitmap = MediaStore.Images.Media.getBitmap(this.getContentResolver(), imageUri);
File compressedFile1 = Utilities.saveImage(this, bitmap);
}
public static File saveImage(Context context, Bitmap imgBitmap) {
File mediaFile = null;
try {
//Bitmap imgBitmap = (Bitmap) data.getExtras().get("data");
File sd = Environment.getExternalStorageDirectory();
File imageFolder = new File(sd.getAbsolutePath() + File.separator +
".FOSImages");
if (!imageFolder.isDirectory()) {
imageFolder.mkdirs();
}
mediaFile = new File(imageFolder + File.separator + "fos_" +
System.currentTimeMillis() + ".jpg");
FileOutputStream fileOutputStream = new FileOutputStream(mediaFile);
imgBitmap.compress(Bitmap.CompressFormat.JPEG, 90, fileOutputStream);
fileOutputStream.close();
return mediaFile;
} catch (Throwable throwable) {
throwable.printStackTrace();
}
return mediaFile;
}
It's appearing in Gallery because you are using getExternalStorageDirectory()
, this returns a public path accessible by all apps. 它出现在Gallery中是因为您使用的是
getExternalStorageDirectory()
,这将返回所有应用程序都可以访问的公共路径。 So one solution is to use a private external path context.getExternalFilesDir(Environment.DIRECTORY_PICTURES), folderName)
, the files saved here will not be accessible by MediaScanner
and therefore not visible in the Gallery, although they will be deleted when your app is deleted. 所以,一个解决方案是使用专用的外部路径
context.getExternalFilesDir(Environment.DIRECTORY_PICTURES), folderName)
,这里保存的文件不会被访问MediaScanner
,因此在图库中不可见,但是当你的应用程序被删除,他们将被删除。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.