I want to get the file extension of a file I picked with Intent.ACTION_OPEN_DOCUMENT. How to get it?
This is how I start the picker:
private void startFilePicker(){
Intent intent = new Intent(Intent.ACTION_OPEN_DOCUMENT);
intent.addCategory(Intent.CATEGORY_OPENABLE);
intent.setType("*/*");
intent.putExtra(Intent.EXTRA_ALLOW_MULTIPLE, true);
startActivityForResult(intent, CODE_ACTION_OPEN_DOCUMENT_FILE);
}
This is callback when file is picked:
@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
super.onActivityResult(requestCode, resultCode, data);
//region New Picker
if (requestCode == CODE_ACTION_OPEN_DOCUMENT_FILE){
if (resultCode == RESULT_OK){
if (data != null){
if (data.getData() != null){
Uri uri = data.getData();
//Get file extension here.
}
}
}
}
}
When I try to get file path by doing uri.getPath()
, I get something like image:105571
, or acc=1;doc=9204
. So I can't get it from path.
The question is how to determine the file extension of picked file?