Example usage for android.webkit MimeTypeMap getFileExtensionFromUrl

List of usage examples for android.webkit MimeTypeMap getFileExtensionFromUrl

Introduction

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

Prototype

public static String getFileExtensionFromUrl(String url) 

Source Link

Document

Returns the file extension or an empty string if there is no extension.

Usage

From source file:Main.java

public static String getMimeType(String fileUrl) {
    String extension = MimeTypeMap.getFileExtensionFromUrl(fileUrl);
    return MimeTypeMap.getSingleton().getMimeTypeFromExtension(extension);
}

From source file:Main.java

public static String extension(String file) {
    return MimeTypeMap.getFileExtensionFromUrl(file);
}

From source file:Main.java

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

From source file:Main.java

/**
 * Tries to retrieve mime types from file extension
 * @param url//from  w  w  w.  ja  v  a 2 s  . co  m
 * @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

static boolean isVideo(File file) {

    Uri uri = Uri.fromFile(file);/*  w  w  w . j  a  v  a  2  s  . co  m*/
    String type = MimeTypeMap.getSingleton()
            .getMimeTypeFromExtension(MimeTypeMap.getFileExtensionFromUrl(uri.toString()));

    if (type == null)
        return false;
    else
        return (type.toLowerCase().startsWith("video/"));
}

From source file:Main.java

public static boolean isPicture(File file) {

    Uri uri = Uri.fromFile(file);/*from w ww. ja va  2s. c  o m*/
    String type = MimeTypeMap.getSingleton()
            .getMimeTypeFromExtension(MimeTypeMap.getFileExtensionFromUrl(uri.toString()));

    if (type == null)
        return false;
    else
        return (type.toLowerCase().startsWith("image/"));
}

From source file:Main.java

public static String getMimeType(String url) {
    String type = null;//from www . j a  va2  s. c  o  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 getFileExtensionFromUrl(String url) {
    return MimeTypeMap.getFileExtensionFromUrl(url);
}

From source file:Main.java

public static Intent getOpenFileIntent(File file) {
    if (file == null || !file.exists() || !file.isFile()) {
        return null;
    }//w w  w .  j  a va2  s  . com
    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

/**
 * Get MimeType./*www.ja  v  a 2s. co  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;
}