之前写过 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 就能使用这张图片了。


更多相关文章

  1. 开箱即用!Android四款系统架构工具
  2. Android 系统(125)---Android通过Dialer实现暗码启动
  3. Android PNG渐变背景图片失真问题
  4. 浅谈Android系统进程间通信(IPC)机制Binder中的Server和Client获得
  5. CardView 添加背景图片、改变颜色、水波纹效果的方法
  6. android 拉伸图片

随机推荐

  1. Android(安卓)Selector Shape使用详解
  2. Android之背景图片设置为重复而不是默认
  3. 收藏的Android非常好用的组件或者框架。
  4. android调节屏幕亮度
  5. android 屏幕上面画线
  6. Android开机广播和关机广播
  7. android 全屏幕显示以及竖屏显示
  8. Android(安卓)GridView 通过seletor 设置
  9. Android(安卓)和 SQLite 基本数据类型
  10. android-logging-log4j - Logging with L