I came across many questions in stackoverflow regarding this error but non of them found explaining a proper solution for my scenario.
In my android application I have to allow the user to click a button to open the Gallery and to select an image. And then needs to load that specific selected image to an ImageView in my layout(UI).
Doing this is quite fine. Following is the code I am using to achieve this.
In Upload button click ->
Intent intent = new Intent();
intent.setType("image/*");
intent.setAction(Intent.ACTION_GET_CONTENT);
startActivityForResult(Intent.createChooser(intent,"Select Picture"), REQUEST_UPLOAD_IMG);
And then onActivityResult ->
@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data)
{
//super.onActivityResult(requestCode, resultCode, data);
if(resultCode == Activity.RESULT_OK)
{
if(requestCode==REQUEST_UPLOAD_IMG)
{
Uri selectedImageURI = data.getData();
uploadImgVW.setImageURI(selectedImageURI);
}
else
{
Toast.makeText(MainActivity.this, "You can only select an Image.", Toast.LENGTH_LONG).show();
}
}
}
But if user select an image with a higher size (Like 2MB of size), the application quit with the following Error. But It's quite fine with normal(KB level) images and wonder what I can do for this issue(To handle this error situation). Thanks...
Error ->
06-20 16:43:58.445: E/AndroidRuntime(2075): FATAL EXCEPTION: main
06-20 16:43:58.445: E/AndroidRuntime(2075): java.lang.OutOfMemoryError: bitmap size exceeds VM budget