-1

I want to pick an image from gallery and then get the path of the image on SD card

     Intent intent = new Intent();
     intent.setType("image/*");
     intent.putExtra("crop", "true");
     intent.setAction(Intent.ACTION_PICK);
     startActivityForResult(Intent.createChooser(intent,
             "Select Picture"), 1);

then Activity result as

 public void onActivityResult(int requestCode, int resultCode, Intent data) {

    String tempImage = null;
    File f = null ;
        if (resultCode == RESULT_OK && requestCode == 1 && data!=null) 
        {
                        Uri selectedImageUri = data.getData(); // always null Uri WHY?
                        selectedImagePath = getPath(selectedImageUri);
                        if(selectedImagePath!=null)
                        {

                 ........

and the getPath method

public  String getPath(Uri uri) {
        String[] projection = { MediaStore.Images.Media.DATA };
        Cursor cursor = managedQuery(uri, projection, null, null, null);
        int column_index = cursor
                .getColumnIndexOrThrow(MediaStore.Images.Media.DATA);
        cursor.moveToFirst();
        return cursor.getString(column_index);
    }

The problem is Uri selectedImageUri = data.getData(); giving the null value. Yesterday it was working fine.

even intent is not null.

I tried cleaning the project but the problem still remain same.

Thanks in Advance!!

*UPDATE SOLUTION *

solution is HERE

Community
  • 1
  • 1
Sunny
  • 14,522
  • 15
  • 84
  • 129

1 Answers1

0

This one is working in my application:

To start Image Chooser :

    Intent intent = new Intent();
    intent.setType("image/*");
    intent.setAction(Intent.ACTION_PICK);
    startActivityForResult(Intent.createChooser(intent,"Select Picture"), 201);

The function to get SD Card path from URI.

private String decodePath(Uri data)
{        
     Cursor cursor = getContentResolver().query(data, null, null, null, null);
     cursor.moveToFirst(); 
     int idx = cursor.getColumnIndex(ImageColumns.DATA);
     String fileSrc = cursor.getString(idx);   
     return fileSrc;
}
Sadeshkumar Periyasamy
  • 4,848
  • 1
  • 26
  • 31
  • thanks for your response actually Uri is null so when i'll pass Uri in decodePath it will not work. The problem is null Uri which i am getting. – Sunny Mar 07 '12 at 06:37
  • try removing intent.putExtra("crop", "true"); – Anirudh Mar 07 '12 at 06:45
  • you are right Anirudth after removing that line code is working. But i want cropped image. – Sunny Mar 07 '12 at 06:46