我試圖將圖像文件保存到外部存儲。我可以將圖片保存到SD卡,但不會顯示在Android圖庫應用程序中。我試過這種方法:用新創建的位圖更新Android圖像庫
File path = Environment.getExternalStorageDirectory();
File f = new File(path + "/mydirectory/" + imageName + "_" + System.currentTimeMillis() + ".jpg");
FileOutputStream fos = new FileOutputStream(f);
f.mkdirs();
b.compress(CompressFormat.JPEG, 100, fos);
fos.close();
Uri contentUri = Uri.fromFile(f);
Intent mediaScanIntent = new Intent("android.intent.action.MEDIA_SCANNER_SCAN_FILE");
mediaScanIntent.setData(contentUri);
getApplicationContext().sendBroadcast(mediaScanIntent);
但它不顯示在畫廊。任何人都可以指出我正確的方向來解決這個問題嗎?
感謝蘇倫德拉+1你:)它完美 –
它的回答 – Jayesh
不要忘記正常使用... +1在AndroidManifest.xml中用' '設置WRITE_EXTERNAL_STORAGE權限。 –