[英]How to get extension of file from URI?
I am selecting a file from the galley and then in onActivityResult, I am getting the Uri.我从厨房中选择一个文件,然后在 onActivityResult 中,我得到了 Uri。 Now I want to get the extension of the file from Uri.现在我想从 Uri 获取文件的扩展名。 I tried many ways but none of them worked.我尝试了很多方法,但都没有奏效。 Please help.请帮忙。
@Override
public void onActivityResult(int requestCode, int resultCode, Intent data) {
Uri uri = data.getData();
}
String extension = data.getPath().substring(data.getPath().lastIndexOf("."))
Use the content resolver to query the uri for.DISPLAY_NAME.使用内容解析器查询 .DISPLAY_NAME 的 uri。
The name comes with extension.该名称带有扩展名。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.