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();
}