1

In my app I am taking a screenshot and saving it to the gallery but the problem is that the images are not showing in gallery,only when I manually go to file explorer can see the images. I am using the following code for it-

  try {
                Date currentTime =    Calendar.getInstance().getTime();


            View v1 = getActivity().getWindow().getDecorView().getRootView();
                v1=view.findViewById(R.id.frm);
                v1.setDrawingCacheEnabled(true);

                Bitmap bitmap = Bitmap.createBitmap(v1.getDrawingCache());
                v1.setDrawingCacheEnabled(false);


                File file= Environment.getExternalStorageDirectory();
                File dir=new File(file+"/Allinone/");
                dir.mkdir();
                File mp=new File(dir,currentTime+".jpg");

                FileOutputStream outputStream = new FileOutputStream(mp);
                int quality = 100;
                bitmap.compress(Bitmap.CompressFormat.JPEG, quality, outputStream);
                outputStream.flush();
                outputStream.close();

                Toast.makeText(getActivity(),"Saved Successfully", Toast.LENGTH_SHORT).show();


            } catch (Throwable e) {

                e.printStackTrace();
                Toast.makeText(getActivity(),"Error Occured,Please Check for permissions", Toast.LENGTH_SHORT).show();

            }
ghu
  • 41
  • 6
  • 1
    https://stackoverflow.com/questions/32789157/how-to-write-files-to-external-public-storage-in-android-so-that-they-are-visibl – CommonsWare Jan 22 '18 at 19:30

1 Answers1

0

There may be a problem with the gallery, so I suggest if you want to display those images, use a link to the place in file explorer where these are stored!