Exceptional
Exceptional

Reputation: 3004

onActivityResult to pick image with putExtra()

Want to set the value RESULT from the following part and should retrieve it in the onActivityResult...

Following is the code.

Intent intent = new Intent();
                intent.setType("image/*");
                intent.setAction(Intent.ACTION_GET_CONTENT);
                System.out.println("Select Display Picture, but");
                intent.putExtra("RESULT", "RESULT");
                activity.startActivityForResult(
                        Intent.createChooser(intent, "Select Display Picture"),
                        Credentials.BROWSE_PIC);
                activity.setResult(Credentials.BROWSE_PIC, intent);


@Override
    protected void onActivityResult(int requestCode, int resultCode, Intent data) {
        super.onActivityResult(requestCode, resultCode, data);
        if (requestCode == Credentials.BROWSE_PIC
                && resultCode == Activity.RESULT_OK && null != data) {
//returning null always here..
            System.out.println("OnActivityResult came in::: "
                    + data.getStringExtra("RESULT"));
            Uri selectedImage = data.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 picturePath = cursor.getString(columnIndex);
            cursor.close();

        }

Upvotes: 1

Views: 547

Answers (1)

Lavekush
Lavekush

Reputation: 6166

You are using implicit Intent, you can not put anything in this intent because every implicit intent is defined by others.

If you want to add something then you can use your own Global Bundle object for the same.

Here are important link for you:

You can see answer By Lavekush Agrawer for using Global Bundle Object. here access the variable in activity in another class

Android Intents - Tutorial

Upvotes: 2

Related Questions