0

I have to implement an app which uploads the image on the server as soon as the user opens any of his/her images from the phone gallery section.My question is how to get the image path? Thanks in advance

Sachin Prasad
  • 5,365
  • 12
  • 54
  • 101
Ishant
  • 53
  • 9

1 Answers1

0

First call this intent to pick image from gallery :

private static final int SELECT_PHOTO = 100;

Intent photoPickerIntent = new Intent(Intent.ACTION_PICK);
photoPickerIntent.setType("image/*");
startActivityForResult(photoPickerIntent, SELECT_PHOTO);

When you are done with select image from gallery it will automatically call this onActivityResult method :

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

        switch (requestCode) {
        case SELECT_PHOTO:
            if (resultCode == RESULT_OK) {
                Uri selectedImage = imageReturnedIntent.getData();
                try {
                    yourImageView.setImageBitmap(decodeUri(selectedImage));
                } catch (FileNotFoundException e) {
                    e.printStackTrace();
                }
            }
        }
    }

You will get image path in selectedImage variable.

Thanks.

Pratik Sharma
  • 13,307
  • 5
  • 27
  • 37
  • thanks for this and iam aware of it...but my scenario is different.I want a background app for me to do this or some kind of broadcast receiver which triggers on native gallery selection from android mobile. – Ishant Jan 07 '13 at 11:01