Updated 22 April 2017
There are some cases occur out of memory Exception when uploading an image from the camera, this happened because of no memory available to upload the image. So how we handle the Exception?
By using the BitmapFactory.Options class.
1 |
final BitmapFactory.Options options = new BitmapFactory.Options(); |
the following code to apply in our code when getting the result is Activity.RESULT_OK from the camera.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 |
if (requestCode == REQUEST_CAMERA && resultCode == Activity.RESULT_OK) { Bitmap clickedImage; String filename = ""; String path = mUri.getPath(); // write our form for handling out of memory final BitmapFactory.Options options = new BitmapFactory.Options(); options.inSampleSize = 8; try { if (path.length() > 0) { filename = path.substring(path.lastIndexOf("/") + 1, path.length()); // clickedImage = BitmapFactory.decodeFile(path); clickedImage = BitmapFactory.decodeFile(path, options);// add option 2 power image upload setImageAndName(clickedImage, filename); } }catch (OutOfMemoryError e){ Toast.makeText(this,"Not enough memory please delete some Files", Toast.LENGTH_SHORT).show(); } } |
If you have more details or questions, you can reply to the received confirmation email.
Back to Home
Be the first to comment.