This is my very first post. Please correct me if there are any mistakes :)
I'm having a problem of displaying images (captured through my app) in a specific folder in Gallery. I've managed to saved it in my app's folder in the directory but when I proceed to the gallery, it won't show my app's folder (when first created) and images captured UNLESS I restart my phone.
I'm running on Android 4.4.4 and according to this , it seems to be a bug?
Anyway, here's my code:
private void savePic() {
dir_path = "TravelBuddy";
travelBuddyDir = new File(Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_PICTURES), dir_path);
timeStamp = new SimpleDateFormat("yyyyMMdd_HHmmss").format(new Date());
imgName = (timeStamp + ".jpg");
output = null;
File imagePath = new File(travelBuddyDir, imgName);
try {
output = new FileOutputStream(imagePath);
bmp.compress(Bitmap.CompressFormat.JPEG, 100, output);
output.flush();
output.close();
MediaStore.Images.Media.insertImage(getActivity().getContentResolver(), bmp,
imgName, imgName);
} catch (Exception e) {
e.printStackTrace();
}
}
Whereby the method above will be called in the onActivityResult(int requestCode, int resultCode, Intent data) method below:
public void onActivityResult(int requestCode, int resultCode, Intent data) {
switch (resultCode) {
case 1: {
if (resultCode == RESULT_OK) {
savePic();
}
break;
}
This is my method of checking and creating the directory before saving the image captured: (The outcome path: /storage/emulated/0/Pictures/TravelBuddy)
private void checkDir() {
if(Environment.MEDIA_MOUNTED.equals(Environment.getExternalStorageState())) {
dir_path = "TravelBuddy";
travelBuddyDir = new File(Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_PICTURES), dir_path);
if (!travelBuddyDir.exists() && (!travelBuddyDir.isDirectory())) {
travelBuddyDir.mkdir();
System.out.println("New directory has been created");
} else {
System.out.println("Directory already exists!");
}
} else {
System.out.println("No storage available");
}
}
I'm new to this whole thing(capturing, storing, etc.) and have been trying for days. Any help is much appreciated. Thank you in advance!