包括媒体刷新我的代码?

时间:2015-06-11 14:55:40

标签: java android

我正在将图像下载到SDCARD上的文件夹中。由于图像和我的文件夹在画廊中没有立即可见,我试图让我更新并在图库中显示文件夹/图像。在我的代码中显示如何执行此操作?

private void downloadImage() {
if (future != null) {
    //set the callback and start downloading
    future.withResponse().setCallback(new FutureCallback<Response<InputStream>>() {
        @Override
        public void onCompleted(Exception e, Response<InputStream> result) {
            boolean success = false;
            if (e == null && result != null && result.getResult() != null) {
                try {
                    //prepare the file name
                    String url = mSelectedImage.getUrl();
                    String fileName = url.substring(url.lastIndexOf('/') + 1, url.length());
                    //create a temporary directory within the cache folder
                    File dir = Utils.getAlbumStorageDir("wall-tx");
                    //create the file
                    File file = new File(dir, fileName);
                    if (!file.exists()) {
                        file.createNewFile();
                    }

                    //copy the image onto this file
                    Utils.copyInputStreamToFile(result.getResult(), file);

                    //animate the first elements
                    animateCompleteFirst(true);

                    //Broadcast the Media Scanner Intent to trigger it

                    success = true;
                } catch (Exception ex) {
                    Log.e("walltx", ex.toString());
                }

                //animate after complete
                animateComplete(success);
            } else {
                animateReset(true);
            }
        }
    });
}

}

0 个答案:

没有答案