3

I have been researching on this but I am not able to find an answer for this.

I am picking an image from the gallery using media store intent and I am able to get the image file path in onActivityResult method. (I know how to get the URI in the intent and filepath).

I am passing in some intent extras on starting the activity (startActivityForResult) but all the intent extras are null.

Code snippets (in case):

This is my onActivityResult code which is working and i get the image path

/* On activity result from image button */
    @Override
    protected void onActivityResult(int requestCode, int resultCode, Intent data) {
        System.out.println("Result Code" + resultCode);
        if(requestCode == FavoriteListAdapter.IMAGE_PICK_CODE && data != null && data.getData() != null && resultCode == FragmentActivity.RESULT_OK) {
            Uri _uri = data.getData();

            //User had pick an image.
            Cursor cursor = getContentResolver().query(_uri, new String[] { android.provider.MediaStore.Images.ImageColumns.DATA }, null, null, null);
            cursor.moveToFirst();

            //Link to the image
            String imageFilePath = cursor.getString(0);


            System.out.println("imagefilepath" + imageFilePath);  
            System.out.println(data.getStringExtra("exp"));
            cursor.close();  
        }
    }       

I am starting my activity with startActivityForResult

Intent imageIntent = new Intent(Intent.ACTION_PICK, android.provider.MediaStore.Images.Media.EXTERNAL_CONTENT_URI);
            imageIntent.setType("image/*");
            imageIntent.putExtra("exp", "testing");

            ((FragmentActivity)view.getContext()).startActivityForResult(imageIntent, IMAGE_PICK_CODE);

I should be able to get the string "testing" in onActivityForResult but all I get is null.

Any ideas and suggestions will be appreciated. THnkas a lot.

Guru
  • 916
  • 3
  • 12
  • 22
  • 1
    Starting some system activities appears to not send back original intent data, this question (and linked answer) seem very close to your problem, http://stackoverflow.com/a/16073980/2728623 – pfairbairn Sep 13 '13 at 22:25

1 Answers1

5

Actually I figured it out .. When you are sending an intent to a system activity like MediaStore or the camera etc... the onActivityResult will not have the intent extras you sent while calling the activity.

This is probably by design and will only contain the extras given by the system activity. For instance after picking an image from the gallery, the returning intent from the gallery will only the URI containing the image path.

Same goes to camera or any system activites.

Guru
  • 916
  • 3
  • 12
  • 22
  • 2
    is correct (I found this out the hard way!). Instead I wrote two methods...one that saves whatever variables I wanted to pass in SharedPrefrences and another that retrieves & deletes them. It works extremely well. – Jabari Dec 07 '13 at 01:42