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
Asked
Active
Viewed 284 times
0
-
i hv'nt got any solution yet..no idea – Ishant Jan 07 '13 at 10:42
-
1Yes, you don't have a solution. But have you at least tried using something? Googling for it? Or do you want us to give you complete code? – Raghav Sood Jan 07 '13 at 10:43
-
yes i want you to give me the complete commented code...if you cant den dont panic dear...your time out :) – Ishant Jan 07 '13 at 10:44
-
@Ishant see the solution I have posted that will solve your problem. – Pratik Sharma Jan 07 '13 at 10:58
1 Answers
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