Example usage for android.drm DrmManagerClient getOriginalMimeType

List of usage examples for android.drm DrmManagerClient getOriginalMimeType

Introduction

In this page you can find the example usage for android.drm DrmManagerClient getOriginalMimeType.

Prototype

public String getOriginalMimeType(Uri uri) 

Source Link

Document

Retrieves the MIME type embedded in the original content.

Usage

From source file:Main.java

/**
 * Gets the original mime type of DRM protected content.
 *
 * @param context The context// www  .  j  a  va2  s. c om
 * @param path Path to the file
 * @param containingMime The current mime type of of the file i.e. the
 *            containing mime type
 * @return The original mime type of the file if DRM protected else the
 *         currentMime
 */
public static String getOriginalMimeType(Context context, String path, String containingMime) {
    String result = containingMime;
    DrmManagerClient drmClient = new DrmManagerClient(context);
    try {
        if (drmClient.canHandle(path, null)) {
            result = drmClient.getOriginalMimeType(path);
        }
    } catch (IllegalArgumentException ex) {
        Log.w(TAG, "Can't get original mime type since path is null or empty string.");
    } catch (IllegalStateException ex) {
        Log.w(TAG, "DrmManagerClient didn't initialize properly.");
    }
    return result;
}

From source file:Main.java

/**
 * Return the original MIME type of the given file, using the DRM framework
 * if the file is protected content.// w w  w  .  j  ava 2  s .co m
 */
public static String getOriginalMimeType(Context context, File file, String currentMime) {
    final DrmManagerClient client = new DrmManagerClient(context);
    try {
        final String rawFile = file.toString();
        if (client.canHandle(rawFile, null)) {
            return client.getOriginalMimeType(rawFile);
        } else {
            return currentMime;
        }
    } finally {
        client.release();
    }
}