Androd学习笔记——[转] Android刷新本地相册 - lingyun1120
2011-12-27 14:48:0 Author: www.cnblogs.com(查看原文) 阅读量:4 收藏

发现程序把图片保存到sdcard后,在相册里面找不到,只有在sdcard重新装载后会出现图片;

原来图片保存到本地后,需要通知相册,加上如下代码就好了:

Uri localUri = Uri.fromFile(imageFile);

Intent localIntent = new Intent(Intent.ACTION_MEDIA_SCANNER_SCAN_FILE, localUri);

sendBroadcast(localIntent);

imageFile是图片的File对象;

或者

ContentValues localContentValues = new ContentValues();

localContentValues.put("_data", imageFile.toString());

localContentValues.put("description", "save image ---");

localContentValues.put("mime_type", "image/jpeg");

ContentResolver localContentResolver = getContentResolver();

Uri localUri = MediaStore.Images.Media.EXTERNAL_CONTENT_URI;

localContentResolver.insert(localUri, localContentValues);


文章来源: https://www.cnblogs.com/lingyun1120/archive/2011/12/27/2303560.html
如有侵权请联系:admin#unsafe.sh