Example usage for android.webkit MimeTypeMap getSingleton

List of usage examples for android.webkit MimeTypeMap getSingleton

Introduction

In this page you can find the example usage for android.webkit MimeTypeMap getSingleton.

Prototype

public static MimeTypeMap getSingleton() 

Source Link

Document

Get the singleton instance of MimeTypeMap.

Usage

From source file:Main.java

public static String getMimeType(String uri) {
    String type = null;//w w w .j  av  a  2s .c  o m
    String extension = MimeTypeMap.getFileExtensionFromUrl(uri);
    if (extension != null) {
        MimeTypeMap mime = MimeTypeMap.getSingleton();
        type = mime.getMimeTypeFromExtension(extension);
    }
    return type;
}

From source file:Main.java

public static String getMIMEType(File var0) {
    String var1 = "";
    String var2 = var0.getName();
    String var3 = var2.substring(var2.lastIndexOf(".") + 1, var2.length()).toLowerCase();
    var1 = MimeTypeMap.getSingleton().getMimeTypeFromExtension(var3);
    return var1;
}

From source file:Main.java

/**
 * Tries to retrieve mime types from file extension
 * @param url/* ww  w .  j  a v a 2  s  .  com*/
 * @return
 */
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;
}

From source file:Main.java

public static String getMIMETypeFromFileName(String fileName) {
    if (fileName == null) {
        return null;
    }/*from  www .  j ava  2s .  c o m*/
    String extension = getExtensionFromFileName(fileName);
    if (extension == null) {
        return null;
    }
    return MimeTypeMap.getSingleton().getMimeTypeFromExtension(extension);
}

From source file:Main.java

public static String getMimeType(String url) {
    String type = null;//from w w  w  .j  a  v  a 2 s.co  m
    String extension = MimeTypeMap.getFileExtensionFromUrl(url);
    if (extension != null) {
        MimeTypeMap mime = MimeTypeMap.getSingleton();
        type = mime.getMimeTypeFromExtension(extension);
    }
    return type;
}

From source file:Main.java

public static String getFileExtensionFromMimeType(String mimeType, String defaultExtension) {
    String result = defaultExtension;
    String extension = MimeTypeMap.getSingleton().getExtensionFromMimeType(mimeType);
    if (extension != null) {
        result = extension;//  ww  w . j  a  v  a  2  s.com
    }

    return result;
}

From source file:Main.java

public static Intent getOpenFileIntent(File file) {
    if (file == null || !file.exists() || !file.isFile()) {
        return null;
    }//ww w .j  av  a  2 s .  c om
    String extension = MimeTypeMap.getFileExtensionFromUrl(file.getAbsolutePath());
    String mimeType = MimeTypeMap.getSingleton().getMimeTypeFromExtension(extension);
    if (extension == null || mimeType == null) {
        return null;
    }
    Intent intent = new Intent(Intent.ACTION_VIEW);
    intent.addCategory(Intent.CATEGORY_DEFAULT);
    intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
    intent.setDataAndType(Uri.fromFile(file), mimeType);
    return intent;
}

From source file:Main.java

public static String getMimeType(String filePath) {
    if (TextUtils.isEmpty(filePath)) {
        return "";
    }/*from www  . ja v  a  2  s.  c o  m*/
    String type = null;
    String extension = getExtensionName(filePath.toLowerCase());
    if (!TextUtils.isEmpty(extension)) {
        MimeTypeMap mime = MimeTypeMap.getSingleton();
        type = mime.getMimeTypeFromExtension(extension);
    }
    Log.i(TAG, "url:" + filePath + " " + "type:" + type);

    // FIXME
    if (TextUtils.isEmpty(type) && filePath.endsWith("aac")) {
        type = "audio/aac";
    }

    return type;
}

From source file:Main.java

/**
 * Get MimeType.// www .  j  a  va2s .  c o  m
 *
 * @param url file's url
 * @return file's MimeType
 */
public static String getMimeType(final String url) {
    String type = null;
    String extension = MimeTypeMap.getFileExtensionFromUrl(url);
    if (extension != null) {
        type = MimeTypeMap.getSingleton().getMimeTypeFromExtension(extension);
    }
    return type;
}

From source file:Main.java

public static String getMimeType(String url, String defaultType) {
    MimeTypeMap mtm = MimeTypeMap.getSingleton();
    String extension = MimeTypeMap.getFileExtensionFromUrl(url);
    String mimetype = defaultType;

    if (extension != null) {
        String type = mtm.getMimeTypeFromExtension(extension);
        if (type != null) {
            mimetype = type;//w  w  w.  java 2 s .c o m
        }
    }

    return mimetype;
}