Android添加照片到系统图库

 

 

1 Intent mediaScanIntent = new Intent(Intent.ACTION_MEDIA_SCANNER_SCAN_FILE);
2 mediaScanIntent.setData(Uri.fromFile(imgFile));
3 sendBroadcast(mediaScanIntent);

 

// 把文件插入到系统图库
try {
   MediaStore.Images.Media.insertImage(getContentResolver(), imgFile.getAbsolutePath(), imgFile.getName(), null);
} catch (FileNotFoundException | NullPointerException e) {
   e.printStackTrace();
}
// 通知图库更新
sendBroadcast(new Intent(Intent.ACTION_MEDIA_SCANNER_SCAN_FILE, Uri.parse("file://" + imgFile.getAbsolutePath())));

 

posted @ 2016-02-26 10:14  清苑月明  阅读(536)  评论(0编辑  收藏  举报