Example usage for android.content Intent normalizeMimeType

List of usage examples for android.content Intent normalizeMimeType

Introduction

In this page you can find the example usage for android.content Intent normalizeMimeType.

Prototype

public static @Nullable String normalizeMimeType(@Nullable String type) 

Source Link

Document

Normalize a MIME data type.

Usage

From source file:com.frostwire.android.gui.util.UIUtils.java

/**
 * Opens the given file with the default Android activity for that File and
 * mime type.//w  w w.  ja v  a 2s  . co m
 */
public static void openFile(Context context, String filePath, String mime, boolean useFileProvider) {
    try {
        if (filePath != null && !openAudioInternal(context, filePath)) {
            Intent i = new Intent(Intent.ACTION_VIEW);
            i.setDataAndType(getFileUri(context, filePath, useFileProvider), Intent.normalizeMimeType(mime));
            i.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_GRANT_READ_URI_PERMISSION);
            if (mime != null && mime.contains("video")) {
                if (MusicUtils.isPlaying()) {
                    MusicUtils.playOrPause();
                }
                UXStats.instance().log(UXAction.LIBRARY_VIDEO_PLAY);
            }
            context.startActivity(i);
        }
    } catch (Throwable e) {
        UIUtils.showShortMessage(context, R.string.cant_open_file);
        LOG.error("Failed to open file: " + filePath, e);
    }
}