-2

I'm trying to pick file from sd-card or other path which user like to do that, in this my code get file path from uri return null and i can't resolve this problem. I'm using android default file manager to pick file

@Override
public void onActivityResult(int requestCode, int resultCode, Intent data) {
    if (requestCode == REQUEST_CODE_PICK_VIDEO && resultCode == Activity.RESULT_OK) {
        Uri uri = data.getData();
        Log.e("", "Video URI= " + getRealPathFromURI(context, uri));
    }
}

public String getRealPathFromURI(Context context, Uri contentUri) {
    Cursor cursor = null;
    try {
        String[] proj = {MediaStore.Images.Media.DATA};
        cursor = context.getContentResolver().query(contentUri, proj, null, null, null);
        int column_index = cursor.getColumnIndexOrThrow(MediaStore.Images.Media.DATA);
        cursor.moveToFirst();
        return cursor.getString(column_index);
    } finally {
        if (cursor != null) {
            cursor.close();
        }
    }
}
mahdi pishguy
  • 994
  • 1
  • 14
  • 43

1 Answers1

0

It is not necessary for a URI to content a file path with it. But if there is a file path attached with the URI you can draw it using this solution.

Chetan Ashtivkar
  • 194
  • 2
  • 15