0

How can i get picture from gallery device and send with parameter to other intent.

First i need call this method:

public void selectImageFromGallery() {
        try{
            Intent intent = new Intent();
            intent.setType("image/*");
            intent.setAction(Intent.ACTION_GET_CONTENT);
            startActivityForResult(Intent.createChooser(intent,"Select an picture"), SELECT_IMAGE);
        }catch(Exception e){
            e.printStackTrace();
        }
    }

And i have this in method StartActivityForResult

@Override
      protected void onActivityResult(int requestCode, int resultcode, Intent intent)
      {
          super.onActivityResult(requestCode, resultcode, intent);

          if (requestCode == 1) 
          {
              if (intent != null && resultcode == RESULT_OK) 
              {              

                    Uri selectedImage = intent.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);
                    cursor.close();
              }
          }
      }

But not works! when i select an picture from gallery nothing happend.

I need select an picture from gallery device and to send other intent.

Somebody have some idea i thanks a lot.

lfrancatto
  • 107
  • 1
  • 1
  • 10
  • Please explain what "But not works!" means. Also, bear in mind that your `MediaStore.Images.Media.DATA` hack may not work, as there is no requirement that the `Uri` you get back comes from the `MediaStore`. – CommonsWare Oct 02 '14 at 13:58
  • add this after cursor.close(); Bitmap bmp = BitmapFactory.decodeFile(picturePath); – ihsanbal Oct 02 '14 at 13:59
  • when i select an picture from gallery nothing happend. – lfrancatto Oct 02 '14 at 14:03
  • ihsanbal I implement this line. but the questions is before select an picture not return to StartActivityForResult. I don`t understood why – lfrancatto Oct 02 '14 at 14:12
  • 2
    Please follow this (http://stackoverflow.com/questions/25524617/intent-to-choose-between-the-camera-or-the-gallery-in-android/26031089#26031089).. here i am choosing image from gallery and then set it into the background of Linearlayout(so u can set in imageView also,it depends).even i am capturing image from camera and again set in the background of layout.So go through code consciously surly it will help u alot. – Rana Pratap Singh Oct 02 '14 at 14:22
  • Welcome @lfrancatto. if u find there(link) something helpful for you then plz upvote that answer. it will be helpful for others. – Rana Pratap Singh Oct 02 '14 at 14:45
  • Guys, this resolved my problem, nice post [link](http://www.theappguruz.com/blog/android-take-photo-camera-gallery-code-sample/) – lfrancatto Oct 02 '14 at 16:19

0 Answers0