In my application, I'm opening the Android default gallery to select and image. The result is the path.
When I test the application in my phone, the path is /mnt/sdcard/picturename
but when I test it in my collegue's phone, the path is /sdcard/picturename
This causes a problem because later in my code, I use a substring method to collect only the picturename. and it gives different results depending on whether the path contains /mnt/ or not!
Do u happen to know how can we get the path starting with /sdcard/ ...
??
here is the code I used to open the Gallery :
photo.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
cheminNouvellePhoto.setText("/sdcard/images/..");
Intent intent = new Intent();
intent.setType("image/*");
intent.setAction(Intent.ACTION_GET_CONTENT);
startActivityForResult(
Intent.createChooser(intent, "Select Picture"), 101);
}
});
and the code that returns the path :
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);
}