0

i'm trying to download images from their urls and save them in special folder and yeah i did that but my my Pictures folder doesn't appear in Gallery please any suggestion to solve this problem.

llDownloadWallpaper.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            // set as wallpapers
            lt.setText("Please Wait ...");
            lt.setTranslationY(100);
            lt.show();
            Glide.with(getApplication())
                    .load(url)
                    .asBitmap()
                    .toBytes(Bitmap.CompressFormat.JPEG, 80)
                    .into(new SimpleTarget<byte[]>() {
                        @Override public void onResourceReady(final byte[] resource, GlideAnimation<? super byte[]> glideAnimation) {
                            new AsyncTask<Void, Void, Void>() {
                                @Override protected Void doInBackground(Void... params) {
                                    File sdcard = Environment.getExternalStorageDirectory();
                                    File file = new File( sdcard+ "/ARTApp/"+"ART_"+System.currentTimeMillis()+".jpg");
                                    File dir = file.getParentFile();
                                    try {
                                        if (!dir.mkdirs() && (!dir.exists() || !dir.isDirectory())) {
                                            throw new IOException("Cannot ensure parent directory for file " + file);
                                        }
                                        BufferedOutputStream s = new BufferedOutputStream(new FileOutputStream(file));
                                        s.write(resource);
                                        s.flush();
                                        s.close();

                                    } catch (IOException e) {
                                        e.printStackTrace();
                                        lt.error();
                                    }
                                    return null;
                                }
                            }.execute();
                            lt.success();
                        }
                    })
            ;
        }
    });
}
iFi
  • 27
  • 7
  • What are you doing to make them appear in gallery app? – greenapps May 08 '17 at 18:35
  • Switch device off/on and see... Here they are. – greenapps May 08 '17 at 18:36
  • https://stackoverflow.com/a/32789206/115145 – CommonsWare May 08 '17 at 18:37
  • @CommonsWare i change with this : `File file = new File(Environment.getExternalStoragePublicDirectory( Environment.DIRECTORY_PICTURES), "/ARTApp/"+"ART_"+System.currentTimeMillis()+".jpg");` and works but my pictures appear after some second ( < 10sec) – iFi May 08 '17 at 18:48
  • As I noted in the answer that I linked to, scan your file with `MediaScannerConnection`, so that `MediaStore` knows about them. – CommonsWare May 08 '17 at 18:52

0 Answers0