Android 效率开发之图片保存到图库
16lz
2021-01-23
之前写过 android 拍照的图片保存到系统图库 ,还有Android 保存Glide展示的图片到本地,其实本质都是图片保存到图库。
为了让系统图库和其他应用APP能使用这张图片,我们需要调用系统的扫描让这张图片记录到Media provider 的数据库中,方法如下:
private void galleryAddPic() { Intent mediaScanIntent = new Intent(Intent.ACTION_MEDIA_SCANNER_SCAN_FILE); File f = new File(mCurrentPhotoPath); Uri contentUri = Uri.fromFile(f); mediaScanIntent.setData(contentUri); this.sendBroadcast(mediaScanIntent);}
也可以简写成:
private void galleryAddPic() { Intent mediaScanIntent = new Intent(Intent.ACTION_MEDIA_SCANNER_SCAN_FILE); mediaScanIntent.setData(Uri.fromFile(new File(mCurrentPhotoPath))); this.sendBroadcast(mediaScanIntent);}
这样,系统图库或者第三方的APP 就能使用这张图片了。 更多相关文章
- 开箱即用!Android四款系统架构工具
- Android 系统(125)---Android通过Dialer实现暗码启动
- Android PNG渐变背景图片失真问题
- 浅谈Android系统进程间通信(IPC)机制Binder中的Server和Client获得
- CardView 添加背景图片、改变颜色、水波纹效果的方法
- android 拉伸图片