android(6)
android媒体库不会时时更新媒体文件,可以调用
sendBroadcast(new Intent(Intent.ACTION_MEDIA_SCANNER_SCAN_FILE, Uri.fromFile(new File("/sdcard/Boohee/image.jpg"))););
或者来扫描系统更新媒体文件
final MediaScannerConnection msc = new MediaScannerConnection(mContext, new MediaScannerConnectionClient() {
public void onMediaScannerConnected() {
msc.scanFile("/sdcard/Boohee/image.jpg", "image/jpeg");
public void onScanCompleted(String path, Uri uri) {
Log.v(TAG, "scan completed");
msc.disconnect();
不过最佳方案是如下代码,只更新该图片
public static void saveImageToGallery(Context context, Bitmap bmp) {
File appDir = new File(Environment.getExternalStorageDirectory(), "Boohee");
if (!appDir.exists()) {
appDir.mkdir();
String fileName = System.currentTimeMillis() + ".jpg";
File file = new File(appDir, fileName);
FileOutputStream fos = new FileOutputStream(file);
press(CompressFormat.JPEG, 100, fos);
fos.flush();
fos.close();
} catch (FileNotFoundException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
MediaStore.Images.Media.insertImage(context.getContentResolver(),
file.getAbsolutePath(), fileName, null);
} catch (FileNotFoundException e) {
e.printStackTrace();
context.sendBroadcast(new Intent(Intent.ACTION_MEDIA_SCANNER_SCAN_FILE, Uri.parse("file://" + path)));
参考知识库
* 以上用户言论只代表其个人观点,不代表CSDN网站的观点或立场
访问:16059次
排名:千里之外
原创:21篇
转载:11篇
(1)(1)(2)(4)(1)(1)(5)(2)(5)(2)(3)(4)