将图片保存到本地后,系统图库可以查看图片

来源:互联网 发布:2017诺贝尔奖预测知乎 编辑:程序博客网 时间:2024/04/30 06:32
File f = new File(path);//path图片的路径
try {
MediaStore.Images.Media.insertImage(mContext.getContentResolver(), f.getAbsolutePath(), f.getName(), null);//插入图库
} catch (FileNotFoundException e) {
e.printStackTrace();
}

mContext.sendBroadcast(new Intent(Intent.ACTION_MEDIA_SCANNER_SCAN_FILE, Uri.parse("file://" + path)));//发送广播通知图库更新

我在使用的过程中出现 Logcat 中提示 open failed: ENOENT (No such file or directory) 以及出现 java.lang.NullPointerException: Attempt to invoke virtual method 'void android.graphics.Bitmap.recycle()' on a null object 异常均是因为path路径下的文件不存在

0 0