保存图片到相册
本文主要介绍保存图片到相册的几种方式。其本质上并没有把图片保存到相册中,实际上是保存在SD卡下自定义的文件夹中,目的只是让 QQ 和 微信 在选择照片的时候立刻显示,注: 其实 QQ 和 微信 也是这样做的 。 方式1-扫描文件通知相册更新 // 通知相册更新 Intent intent = new Intent(Intent.ACTION_MEDIA_SCANNER_SCAN_FILE); Uri uri = Uri.fromFile(file); intent.setData(uri); context.sendBroadcast(intent); 方式1-错误操作 MediaStore.Images.Media.insertImage(context.getContentResolver(), file.getAbsolutePath(), "name", "description"); // 通知相册更新 Intent intent = new Intent(Intent.ACTION_MEDIA_SCANNER_SCAN_FILE); Uri uri = Uri.fromFile(file); intent.setData(uri); context.sendBroadcast(intent); 对比 方式1 和 错误方式 ,我们可以发现其实就是多了一行