发现程序把图片保存到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);
时间: 2024-11-13 00:47:10