Select gallery image in Android causing problem

I am using very simple code to select image from gallery, it works on my phone. but testing it on three to four phones (Galaxy S3, Tablet, etc.) it doesn't work.

Environment: if the image size I took or was in the gallery below 500KB then it works

Environment It Does'nt Work: if the image size I took or was in the gallery above 500kb then it works

ImageView myimg;

    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        // Toast.makeText(this, UUID.randomUUID().toString(),
        // Toast.LENGTH_LONG).show();

        myimg = (ImageView) findViewById(R.id.imageView1);

        mybutton = (Button) findViewById(R.id.myButton);
        mybutton.setOnClickListener(this);

    }

    public void onClick(View v) {

        if (v == mybutton) {

            Intent intent = new Intent(Intent.ACTION_GET_CONTENT);
            intent.setType("image/*");
            startActivityForResult(intent, 0);

        }

    }

    @Override
    protected void onActivityResult(int requestCode, int resultCode,
            Intent imageReturnedIntent) {
        switch (requestCode) {
        case 0:
            if (resultCode == RESULT_OK) {
                Uri selectedImage = imageReturnedIntent.getData();
                String[] filePathColumn = { MediaStore.Images.Media.DATA };

                Cursor cursor = getContentResolver().query(selectedImage,
                        filePathColumn, null, null, null);
                cursor.moveToFirst();

                int columnIndex = cursor.getColumnIndex(filePathColumn[0]);
                String filePath = cursor.getString(columnIndex); // file path of
                                                                    // selected
                                                                    // image
                cursor.close();
                // Convert file path into bitmap image using below line.
                Bitmap yourSelectedImage = BitmapFactory.decodeFile(filePath);

                // put bitmapimage in your imageview
                myimg.setImageBitmap(yourSelectedImage);
            }
        }

    }

      

Can anyone please advise on how to handle this situation?

Any help would be appreciated.

+3
android imageview android-gallery


source to share


No one has answered this question yet

Check out similar questions:

3606
Close / hide Android soft keyboard
3295
Why is the Android emulator so slow? How can we speed up the development of an Android emulator?
3288
Correct use cases for Android UserManager.isUserAGoat ()?
2609
Is there a unique identifier for an Android device?
2510
How to persist android activity state by persisting instance state?
2097
Is there a way to run Python on Android?
1844
What is "Context" on Android?
1832
Lazy loading images in ListView
6
Selecting photo from gallery and viewing in image view
0
How Codes To Load Image From Android Gallery Work



All Articles
Loading...
X
Show
Funny
Dev
Pics