I am using the following code to crop an image using the android crop intent
.
Intent cropIntent = new Intent("com.android.camera.action.CROP", null)
.setDataAndType(picUri,"image/*")
.putExtra("crop", "true")
.putExtra("aspectX", 1)
.putExtra("aspectY", 1)
.putExtra("outputX", 128)
.putExtra("outputY", 128)
.putExtra("scale", true)
.putExtra("return-data", false)
.putExtra("scaleUpIfNeeded", true)
.putExtra(MediaStore.EXTRA_OUTPUT, picUri)
.putExtra("outputFormat", Bitmap.CompressFormat.JPEG.toString());
startActivityForResult(cropIntent, PIC_CROP);
Then I get the cropped picture from this code and I want to save it in a separate folder(created by my app) in the gallery.
Here's the code to save the image :
public static String SaveImage(Bitmap finalBitmap)
{
String root = Environment.getExternalStorageDirectory().toString();
File myDir = new File(root + "/Shopic Snaps");
if(!myDir.exists())
myDir.mkdirs();
Random generator = new Random();
int n = 10000;
n = generator.nextInt(n);
String fname = "Image_"+ n+ GenerateRandomName() +".jpg";
File file = new File (myDir, fname);
if (file.exists ())
file.delete ();
try
{
FileOutputStream out = new FileOutputStream(file);
finalBitmap.compress(Bitmap.CompressFormat.JPEG, 90, out);
out.flush();
out.close();
}
catch (Exception e)
{
e.printStackTrace();
}
return root + "/App Snaps/"+fname;
}
Now this function should save the picture in the gallery and return me the path to the picture.The code runs normally with no errors.
But after performing the tasks when I check the gallery, it is empty. I have no idea why it is not saving the picture in the gallery.
Edit:
I tested the app in another mobile and the pictures are saving fine in them and being showed. So I guess this is a problem in my mobile but I don't know what is causing the problem.