android – ContentResolver总是返回null

前端之家收集整理的这篇文章主要介绍了android – ContentResolver总是返回null前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
我想在我的 Android设备上获取本地文件内容类型.我的代码
File file = new File(uploadPath.replace("file://",""));
Uri uri = Uri.fromFile(file);
ContentResolver contentResolver = getApplicationContext().getContentResolver();
String type = contentResolver.getType(uri);

我的上传路径是file:///storage/emulated/0/DCIM/Camera/20141016_181148.jpg.但是,我总是将我的类型设为null.这是为什么??

解决方法

如果uri方案不是content,则内容解析器将返回null://

猜你在找的Android相关文章