android-将图片添加到gallery应用程序
我有一个可以拍照的应用程序,它们都是全尺寸上传的。我希望它们显示在gallery应用程序中。我正在使用:android-将图片添加到gallery应用程序,android,image-gallery,Android,Image Gallery,我有一个可以拍照的应用程序,它们都是全尺寸上传的。我希望它们显示在gallery应用程序中。我正在使用: private void galleryAddPic() { Intent mediaScanIntent = new Intent(Intent.ACTION_MEDIA_SCANNER_SCAN_FILE); File f = new File(imagepath); Uri contentUri = Uri.fromFile(f); mediaScanI
private void galleryAddPic() {
Intent mediaScanIntent = new Intent(Intent.ACTION_MEDIA_SCANNER_SCAN_FILE);
File f = new File(imagepath);
Uri contentUri = Uri.fromFile(f);
mediaScanIntent.setData(contentUri);
this.sendBroadcast(mediaScanIntent);
}
它在5.0中有效,但在4.3中无效。
imagepath
是一个绝对路径试试这样的方法
private void galleryAddPhoto() {
sendBroadcast(
new Intent(Intent.ACTION_MEDIA_SCANNER_SCAN_FILE,
Uri.parse("file://" + mCurrentFilteredPhotoPath))
);
}
此方法将使用文件的位置将文件添加到库中,其中mCurrentFilteredPhotoPath是一个字符串对象