我正在开发一个应用程序,我正在下载图像并将其存储到内部存储中。在Nougat安装设备上的Gallery中显示下载的图像时遇到问题。
if (Build.VERSION.SDK_INT >= 14)
{
Log.e("-->", " >= 14");
MediaScannerConnection.scanFile(getApplicationContext(), new String[]{event.getFilePath()}, new String[]{".jpg"}, new MediaScannerConnection.OnScanCompletedListener() {
/*
* (non-Javadoc)
* @see android.media.MediaScannerConnection.OnScanCompletedListener#onScanCompleted(java.lang.String, android.net.Uri)
*/
public void onScanCompleted(String path, Uri uri) {
Log.e("ExternalStorage", "Scanned " + path + ":");
Log.e("ExternalStorage", "-> uri=" + uri);
}
});
} else
{
Log.e("-->", " < 14");
sendBroadcast(new Intent(Intent.ACTION_MEDIA_MOUNTED,
Uri.parse("file://" + Environment.getExternalStorageDirectory())));
}
}
public static File getStorageFolder(){
return new File(Environment.getExternalStoragePublicDirectory
(Environment.DIRECTORY_DCIM),"Camera");
}
注意:仅在Nougat设备上出现问题
任何帮助都会得到赞赏,
谢谢
答案 0 :(得分:0)
“。jpg”不是图片的有效MIME类型。
使用mime类型数组
new String[]{"image/jpeg", "image/png"}
而不是
new String[]{".jpg"}