I am using crop intent to crop the image,most of time it run fine,but sometime getting java.lang.SecurityException: Unable to find app for caller android.app.Application
I agree with the Roberto Lombardini's answer. Maybe you can try this solution for simple reference.
Save your bitmap into local first with unique name or you own resource id, you can use UUID
public void savePhotoCache(final String resourceId, final Bitmap bitmap) {
if(bitmap==null)
return;
File imageDir = new File(context.getCacheDir(), "images/yourpackagename");
if (!imageDir.isDirectory())
imageDir.mkdirs();
File cachedImage = new File(imageDir, resourceId);
FileOutputStream output = null;
try {
output = new FileOutputStream(cachedImage);
bitmap.compress(PNG, 100, output);
} catch (IOException e) {
Log.d("CACHED_IMAGE", "Exception writing cache image", e);
} finally {
if (output != null)
try {
output.close();
} catch (IOException e) {
// Ignored
}
}
}
When passing to another activity you only pass resource id and get bitmap data in another activity using this function.
private Bitmap getPhotoCache(final String resourceId) {
File imageDir = new File(context.getCacheDir(), "images/yourpackagename");
if (!imageDir.isDirectory())
imageDir.mkdirs();
File imageFile = new File(imageDir, resourceId);
if (!imageFile.exists() || imageFile.length() == 0)
return null;
Bitmap bitmap = BitmapFactory.decodeFile(imageFile.getAbsolutePath());
if (bitmap != null)
return bitmap;
else {
imageFile.delete();
return null;
}
}
I hope this can help you. :)