private String getPath(Uri uri)
{
if (uri== null) {
return null;
}
String[] projection = { MediaStore.Images.Media.DATA };
Cursor cursor;
if (Build.VERSION.SDK_INT >= 19) {
String wholeID = DocumentsContract.getDocumentId(uri);
String id = wholeID.split(":")[1];
String sel = MediaStore.Images.Media._ID + "=?";
cursor = getContentResolver().query(
MediaStore.Images.Media.EXTERNAL_CONTENT_URI , projection,sel , new String[] { id}, null);
} else
{
cursor = getContentResolver().query(uri, null, null, null,null);
}
String path = null;
try {
int column_index=
cursor.getColumnIndex(MediaStore.Images.Media.DATA);
cursor.moveToFirst();
path = cursor.getString(column_index).toString();
cursor.close();
} catch (NullPointerException e) {
}
return path;
}
{
if (uri== null) {
return null;
}
String[] projection = { MediaStore.Images.Media.DATA };
Cursor cursor;
if (Build.VERSION.SDK_INT >= 19) {
String wholeID = DocumentsContract.getDocumentId(uri);
String id = wholeID.split(":")[1];
String sel = MediaStore.Images.Media._ID + "=?";
cursor = getContentResolver().query(
MediaStore.Images.Media.EXTERNAL_CONTENT_URI , projection,sel , new String[] { id}, null);
} else
{
cursor = getContentResolver().query(uri, null, null, null,null);
}
String path = null;
try {
int column_index=
cursor.getColumnIndex(MediaStore.Images.Media.DATA);
cursor.moveToFirst();
path = cursor.getString(column_index).toString();
cursor.close();
} catch (NullPointerException e) {
}
return path;
}
No comments:
Post a Comment