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;
}
像冠军一样工作谢谢 –