0
我正在製作應用程序,用於下載圖像並將它們存儲到內部存儲器中。在Nougat已安裝的設備上的圖庫中顯示下載的圖像時遇到問題。已下載的圖像未顯示在圖庫中,Android Nougat
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");
}
注意:只在牛軋設備
任何幫助將不勝感激,聞聽問題
感謝
你有外部存儲權限? – Mike
'.jpg'不是MIME類型。除此之外,getFilePath()指向哪裏?如果您的文件位於[內部存儲](https://commonsware.com/blog/2014/04/07/storage-situation-internal-storage.html)上,則其他應用程序(包括媒體掃描程序)無法訪問它。 – CommonsWare
我已更新方法的詳細信息 –