2
因此,在我的應用程序中,我保存了一張照片,然後出現在手機的圖庫中。我認爲它看起來很快,但它不是瞬間的,因爲它而越來越差。我已經看過應用程序,他們立即出現在畫廊中,我希望我也這樣做,以避免更糟糕的評論。我使用sendBroadcast
,我認爲這是最快的方法,但我想我錯了。保存的圖像需要一段時間才能出現在圖庫中
public File savePhoto(File pic,String ext)
{
File mediaStorageDir = new File(Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_PICTURES), "Pics");
// Create the storage directory if it does not exist
if (!mediaStorageDir.exists())
{
if (!mediaStorageDir.mkdirs()) return null;
}
// Create a media file name
String timeStamp = new SimpleDateFormat("yyyyMMdd_HHmmss").format(new Date());
File mediaFile=null;
mediaFile = new File(mediaStorageDir.getPath() + File.separator + "IMG_" + timeStamp + "."+ext);
sendBroadcast(new Intent(Intent.ACTION_MEDIA_MOUNTED, Uri.parse("file://" + new File(Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_PICTURES), "Pics"))));
Toast.makeText(this, "Image Saved", Toast.LENGTH_SHORT).show();
return mediaFile;
}
像冠軍一樣工作謝謝 –