androiddropboxandroid-sdcardandroid-photos

Photo Albums and dropbox application


This is how i am firing an intent to get the picture from photo albums

Intent intent = new Intent();
intent.setType("image/*");
intent.setAction(Intent.ACTION_GET_CONTENT);
startActivityForResult(intent, SELECT_PICTURE);

then from the result i take the path from the

 Uri selectedImageUri = data.getData();

public String getPath(Uri selectedImageUri) {
    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);
}

of selected picture and put that image in sdcard.

But as the dropbox application is also installed then that also comes up and when i select image then Uri comes like

file:///mnt/sdcard/Android/data/com.dropbox.android/files/scratch/FloorPlanImage/7th_floor_new.jpg

and now when i try getPath it crashes . Can you tell me how to fix this so that i can take the path of image and save it in the sdcard?


Solution

  • Well i got what the problem was

    int column_index = cursor.getColumnIndexOrThrow(MediaStore.Images.Media.DATA);
    

    returns nothing as the image was selected from Dropbox and not from photo gallery of android.

    So i did was use the Uri when image is selected and used that to set the ImageView and it worked great.

    Thanks !!