Example usage for android.drm DrmManagerClient canHandle

List of usage examples for android.drm DrmManagerClient canHandle

Introduction

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

Prototype

public boolean canHandle(Uri uri, String mimeType) 

Source Link

Document

Checks whether the given MIME type or URI can be handled.

Usage

From source file:Main.java

/**
 * Gets the original mime type of DRM protected content.
 *
 * @param context The context//from   www  . j  ava  2s . 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 .ja v a 2 s  .  com
 */
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();
    }
}

From source file:Main.java

/**
 * Checks if the Media Type is a DRM Media Type
 *
 * @param drmManagerClient A DrmManagerClient
 * @param mimetype Media Type to check// ww w  . j a v a 2s .  com
 * @return True if the Media Type is DRM else false
 */
public static boolean isDrmMimeType(Context context, String mimetype) {
    boolean result = false;
    if (context != null) {
        try {
            DrmManagerClient drmClient = new DrmManagerClient(context);
            if (drmClient != null && mimetype != null && mimetype.length() > 0) {
                result = drmClient.canHandle("", mimetype);
            }
        } catch (IllegalArgumentException e) {
            Log.w(TAG, "DrmManagerClient instance could not be created, context is Illegal.");
        } catch (IllegalStateException e) {
            Log.w(TAG, "DrmManagerClient didn't initialize properly.");
        }
    }
    return result;
}