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

/**
 * Checks if file passed is an image/* ww w.jav a 2 s. c om*/
 * @param file
 * @return true/false
 */
public static boolean isImage(File file) {
    Uri selectedUri = Uri.fromFile(file);
    String fileExtension = MimeTypeMap.getFileExtensionFromUrl(selectedUri.toString().toLowerCase());
    String mimeType = MimeTypeMap.getSingleton().getMimeTypeFromExtension(fileExtension);

    return (mimeType != null && mimeType.startsWith("image/"));
}

From source file:Main.java

private static String getMimeTypeForExtension(String ext) {
    MimeTypeMap map = MimeTypeMap.getSingleton();
    return map.getMimeTypeFromExtension(ext);
}

From source file:Main.java

public static String getMimetype(String fileName, String def) {
    String mimeType = "application/octet-stream";
    try {//from w  w w  .  ja v  a2s  .com
        MimeTypeMap mimeMap = MimeTypeMap.getSingleton();
        int idx = fileName.lastIndexOf('.');
        if (idx != -1) {
            String ext = fileName.substring(idx + 1);
            mimeType = mimeMap.getMimeTypeFromExtension(ext.toLowerCase());
        }
        if (mimeType == null) {
            mimeType = def == null ? "application/octet-stream" : def;
        }
    } catch (Exception e) {
    }
    return mimeType;
}

From source file:Main.java

public static String getMimeTypeForExtension(String path) {
    String extension = path;// w  w  w.  j  av  a 2s.c  o  m
    int lastDot = extension.lastIndexOf('.');
    if (lastDot != -1) {
        extension = extension.substring(lastDot + 1);
    }
    // Convert the URI string to lower case to ensure compatibility with MimeTypeMap (see CB-2185).
    extension = extension.toLowerCase(Locale.getDefault());
    if (extension.equals("3ga")) {
        return "audio/3gpp";
    }
    return MimeTypeMap.getSingleton().getMimeTypeFromExtension(extension);
}

From source file:com.proofhq.Open.java

/**
 * Returns the MIME type of the file.//from w ww . jav a2  s. c o m
 *
 * @param path
 * @return
 */
private static String getMimeType(String path) {
    String mimeType = null;

    String extension = MimeTypeMap.getFileExtensionFromUrl(path);
    if (extension != null) {
        MimeTypeMap mime = MimeTypeMap.getSingleton();
        mimeType = mime.getMimeTypeFromExtension(extension);
    }

    System.out.println("Mime type: " + mimeType);

    return mimeType;
}

From source file:Main.java

/**
 * @return The MIME type for the given file.
 *///w w w  . j  a  v  a  2  s .  co  m
public static String getMimeType(File file) {

    String extension = getExtension(file.getName());

    if (extension.length() > 0)
        return MimeTypeMap.getSingleton().getMimeTypeFromExtension(extension.substring(1));

    return "application/octet-stream";
}

From source file:com.phonegap.plugins.openfilewithexternalapp.OpenFileWithExternalApp.java

public PluginResult execute(String action, JSONArray args, String callbackId) {

    try {/* w w  w  . j a  v  a  2  s . c  om*/

        String filePath = args.getString(0);

        Intent intent = new Intent();

        intent.setAction(android.content.Intent.ACTION_VIEW);

        File fileToOpen = new File(filePath);

        MimeTypeMap mime = MimeTypeMap.getSingleton();

        String extension = fileToOpen.getName().substring(fileToOpen.getName().lastIndexOf(".") + 1)
                .toLowerCase();

        String type = mime.getMimeTypeFromExtension(extension);

        intent.setAction(Intent.ACTION_VIEW);

        Uri uri = Uri.fromFile(fileToOpen);

        intent.setDataAndType(uri, type);

        this.ctx.startActivity(intent);
    }

    catch (JSONException e) {

        e.printStackTrace();

    }

    PluginResult mPlugin = new PluginResult(PluginResult.Status.NO_RESULT);

    return mPlugin;
}

From source file:Main.java

/**
 * Returns the MIME type of a document, from its URL.
 *
 * @param url the document url//from  www  . jav  a2 s.c o  m
 * @return the document MIME type
 */
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);
    }
    if (null == type) {
        type = "application/octet-stream";
    }
    return type;
}

From source file:no.digipost.android.utilities.FileUtilities.java

public static String getMimeType(File file) {
    MimeTypeMap mime = MimeTypeMap.getSingleton();
    String ext = FilenameUtils.getExtension(file.getName());
    return mime.getMimeTypeFromExtension(ext);
}

From source file:org.mariotaku.twidere.util.SaveFileTask.java

public static SaveFileTask saveImage(final Activity activity, final File source) {
    final String mimeType = Utils.getImageMimeType(source);
    final MimeTypeMap map = MimeTypeMap.getSingleton();
    final String extension = map.getExtensionFromMimeType(mimeType);
    if (extension == null)
        return null;
    final File pubDir = Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_PICTURES);
    final File saveDir = new File(pubDir, "Twidere");
    return new SaveFileTask(activity, source, mimeType, saveDir);
}