我正在开发一个 Android 应用程序,需要使用文件格式过滤文件。我真正想做的是:
输入:“jpg”=>输出:“图像”
输入:“mp3”=> 输出:“音频”
输入:“mov”=> 输出:“视频”
是否有任何 Android API 可以执行此操作,或者我必须手动将此信息存储在我的应用程序中。
最佳答案
您可以使用MimeTypeMap类将返回类似“text/plain”的内容。 您还可以阅读 mime 类型 here
// the File name or Url
public static String getMimeType(String url)
{
String type = null;
String extension = MimeTypeMap.getFileExtensionFromUrl(url);
if (extension != null) {
MimeTypeMap mime = MimeTypeMap.getSingleton();
type = mime.getMimeTypeFromExtension(extension);
}
return type;
}
关于android - 是否有任何android API可以使用文件格式获取文件类型,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29507861/