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())));