相关疑难解决方法(0)

如何确定android中的MIME类型?

假设我有一个完整的文件路径,如:(/ sdcard/tlogo.png).我想知道它的mime类型.

我为它创建了一个函数

public static String getMimeType(File file, Context context)    
{
    Uri uri = Uri.fromFile(file);
    ContentResolver cR = context.getContentResolver();
    MimeTypeMap mime = MimeTypeMap.getSingleton();
    String type = mime.getExtensionFromMimeType(cR.getType(uri));
    return type;
}
Run Code Online (Sandbox Code Playgroud)

但是当我调用它时,它返回null.

File file = new File(filePath);
String fileType=CommonFunctions.getMimeType(file, context);
Run Code Online (Sandbox Code Playgroud)

filesystems android mime-types

162
推荐指数
11
解决办法
12万
查看次数

是什么导致Android的ContentResolver.query()返回null?

在什么条件下ContentResolver.query()返回null而不是游标对象?我之前已经有了空游标但只是意识到该方法也可以返回null.但是,我无法追踪发生这种情况的情况.

android

60
推荐指数
2
解决办法
2万
查看次数

标签 统计

android ×2

filesystems ×1

mime-types ×1