当我保存图片时,我希望图片显示在图库中,而不仅仅是内部存储内部,例如应用壁纸,facebook messenger
我的代码,点击按钮
Final test accuracy = 100.0%
INFO:tensorflow:Froze 2 variables.
INFO:tensorflow:Froze 2 variables.
Converted 2 variables to const ops.
功能saveImage
holder.img_download.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
File dir = new File(Environment.getExternalStorageDirectory(), "/Wallpapers");
if(!dir.exists()) {
dir.mkdirs();
}
Bitmap bitmap = ((BitmapDrawable)holder.img_photo.getDrawable()).getBitmap();
saveImage(bitmap,dir);
}
});
我没有任何问题保存图片,但我想在图库中显示像图像应用程序
答案 0 :(得分:1)
尝试此操作在图库中添加图片:
public void addImageToGallery(final String filePath, final Context context) {
ContentValues contentValues = new ContentValues();
contentValues.put(Images.Media.DATE_TAKEN, System.currentTimeMillis());
contentValues.put(Images.Media.MIME_TYPE, "image/jpeg");
contentValues.put(MediaStore.MediaColumns.DATA, filePath);
context.getContentResolver().insert(Images.Media.EXTERNAL_CONTENT_URI, contentValues);
}
答案 1 :(得分:0)
而不是 File dir = new File(Environment.getExternalStorageDirectory(), "/Wallpapers");
使用
File file = new File(Environment.getExternalStoragePublicDirectory(
Environment.DIRECTORY_PICTURES), albumName);