Hi, I'm doing an app with adnroid in java, I launch an intent to pick up a gallery image. The onActivityResult method returns the Uri of the image, but I need the path of the file. To be able to send it via network to a web server with mysql.Googleando how can I do it, you have sent me to the following method:
public String getRealPathFromURI(Uri contentUri) {
Cursor cursor = null;
try {
String[] proj = {MediaStore.Images.Media.DATA};
cursor = getApplicationContext().getContentResolver().query(contentUri, proj, null, null, null);
int column_index = cursor.getColumnIndexOrThrow(MediaStore.Images.Media.DATA);
cursor.moveToFirst();
Log.i("indexCursor",cursor.getString(column_index));
path=cursor.getString(column_index);
return path;
} finally {
if (cursor != null) {
cursor.close();
}
}
}
According to my modest knowledge it is a query to a content provider, but it does not work, the variable int columnIndex is null. I honestly do not understand what he's doing, and I do not know if he has anything to do with it, I just gave READ_EXTERNAL_STORAGE permission. I think it looks for an integer with the MediaStore.Images.Media.DATA position and never finds it. I can not imagine how that table will have organized the routes to the image files. Any idea why it does not work or how can I get the path of a pickeada gallery image?