1

I know there are lots of question related to my question, but i dint get any answer who will solve my problem, Basically my requirement is choose the image from gallary and set that image back to ImageView of child activity of Tab Activity, but in TabActivity i unable to get call to the onActivityResult() method, Since yesterday i was trying to search another way to solve the issue, as i found onActivityResult() will not be going to work i tried to pass image using bundle but i was getting !!! FAILED BINDER TRANSACTION !!! error, how do i handle above situations, please suggest me way to call onActivityResult() method into child activity of TabActivity, Thanks in advance.

My Code is

  public void openGallary(int req_code) {

    Intent i = new Intent(Intent.ACTION_PICK,
            android.provider.MediaStore.Images.Media.EXTERNAL_CONTENT_URI);

    startActivityForResult(i, req_code);

}

Here is my onActivityResult() method in which i passed requestcode from openGallary() method:

    @Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
    super.onActivityResult(requestCode, resultCode, data);

    if (requestCode == RESULT_LOAD_IMAGE && resultCode == RESULT_OK
            && data != null) {

        Uri pickedImage = data.getData();
        String[] filePath = { MediaStore.Images.Media.DATA };
        Cursor cursor = getContentResolver().query(pickedImage, filePath,
                null, null, null);
        cursor.moveToFirst();
        String imagePath = cursor.getString(cursor
                .getColumnIndex(filePath[0]));

        imgShowLocationImage.setImageBitmap(BitmapFactory
                .decodeFile(imagePath));
        cursor.close();
    }}
Reena
  • 1,368
  • 1
  • 11
  • 25
  • Note: This code works if i run this code in seperate activity means without making same activity as child of tabactivity – Reena May 17 '14 at 09:06

1 Answers1

2

Make this on button pick this will take you to gallery where you will be able to pick image.

                Intent i = new Intent(Intent.ACTION_PICK,android.provider.MediaStore.Images.Media.EXTERNAL_CONTENT_URI);                           
            startActivityForResult(i, LOAD_IMAGE_RESULTS);

And then you call onActivityResult like this .

     if (requestCode == LOAD_IMAGE_RESULTS && resultCode == RESULT_OK && data != null) 
        {

            Uri pickedImage = data.getData();
            String[] filePath = { MediaStore.Images.Media.DATA };         
          Cursor cursor = getContentResolver().query(pickedImage, filePath, null, null, null);
            cursor.moveToFirst();
           String imagePath = cursor.getString(cursor.getColumnIndex(filePath[0]));                        
           // image.setImageBitmap(BitmapFactory.decodeFile(imagePath));      

            image.setImageBitmap(BitmapFactory.decodeFile(imagePath));
           cursor.close();
       }

This way picked image will apper in your ImageView.

user3465277
  • 219
  • 3
  • 10
  • Thanks for reply but still facing same problem :-( , after debugging unable to reach at onActivityResult() method – Reena May 17 '14 at 08:59
  • But onButtonClick yoour app is moving to gallery? – user3465277 May 17 '14 at 09:07
  • Yes my app is moving to the gallery but after selecting image from gallery, onActivityResult() method unable to get call for activity. I was thinking that there could be issue in the passing request code. but no issue with request code, Please go through the note which i mentioned below the question – Reena May 17 '14 at 09:10
  • Is your app crushing, what have you in LogCat? – user3465277 May 17 '14 at 09:12
  • oh w8 i see in your code you have startActivityForResult(i, req_code); place LOAD_IMAGE_RESULTS instead of req_code – user3465277 May 17 '14 at 09:13
  • No my application is not crashing – Reena May 17 '14 at 09:13
  • openGallery(RESULT_LOAD_IMAGE); – Reena May 17 '14 at 09:14
  • you should have button1.setonClickListener(new OnClickListener)) method and there onClick Intent i = new Intent(Intent.ACTION_PICK,android.provider.MediaStore.Images.Media.EXTERNAL_CONTENT_URI); startActivityForResult(i, LOAD_IMAGE_RESULTS); – user3465277 May 17 '14 at 09:16