图片保存到相册

1、发送广播通知相册更新,此方法会将图片复制一份到系统相册中,删除照片互不影响

MediaStore.Images.Media.insertImage(context.getContentResolver(), file.getAbsolutePath(), file.getName(), null);
Intent intent = new Intent(Intent.ACTION_MEDIA_SCANNER_SCAN_FILE);
Uri uri = FileProviderUtils.getUriForFile(context , file);
intent.setData(uri);
context.sendBroadcast(intent);//这个广播的目的就是更新图库,发了这个广播进入相册就可以找到你保存的图片了

2、将当前保存的图片的文件夹添加到相册中,添加删除互相影响,相册中删除了。本地文件夹也会删除

ContentValues contentValues =new  ContentValues(1);
contentValues.put(MediaStore.Images.Media.DATA, file.getAbsolutePath());
context.getContentResolver().insert(MediaStore.Images.Media.EXTERNAL_CONTENT_URI, contentValues);

你可能感兴趣的:(图片保存到相册)