我正在尝试在我的Android设备上获取本地文件的内容类型.我的代码是
File file = new File(uploadPath.replace("file://",""));
Uri uri = Uri.fromFile(file);
ContentResolver contentResolver = getApplicationContext().getContentResolver();
String type = contentResolver.getType(uri);
Run Code Online (Sandbox Code Playgroud)
我的上传路径是file:///storage/emulated/0/DCIM/Camera/20141016_181148.jpg.但是,我总是得到我type的null.这是为什么??
要获取文件的类型,请查看那里:How to certain MIME type of file in android?
可能为空值的原因:
是什么导致Android的ContentResolver.query()返回null?
据我所知,uri 可能不正确。