我正在尝试在我的应用程序中实现 DRM。
但我面临一个问题。canHandle()
总是返回假。
和DrmManagerClient.getOriginalMimeType(Uri)
; http 链接总是返回 null。
但是对于存储中的文件,一切正常。
DrmManagerClient mDrmManager;
mDrmManager = new DrmManagerClient(this);
String testUri = myUrl;
String mimeType = getOriginalMimeType( testUri );
下面是获取 mimetype 的方法,但不幸的是 canHandle() 总是返回 false。
// get MimeType
public String getOriginalMimeType(String uri){
String mime = null;
try {
if( mDrmManager.canHandle(Uri.parse(uri), null) ){
mime = mDrmManager.getOriginalMimeType(Uri.parse(uri));
}
} catch (Exception e) {
Log.w(TAG, e.toString());
}
return mime;
}
我错过了什么吗?
显而易见的是,我使用的 url 可能不好,但我尝试了在另一个应用程序中工作的不同 url,但结果是相同的。
我也在清单文件中设置了 INTERNET 权限。我已经没有想法了,这是什么问题。
在深入研究 DrmManagerClient 源代码后,我注意到 canHandle() 定义如下:
/**
* Checks whether the given MIME type or URI can be handled.
*
* @param uri URI for the content to be handled.
* @param mimeType MIME type of the object to be handled
*
* @return True if the given MIME type or URI can be handled; false if they cannot be handled.
*/
public boolean canHandle(Uri uri, String mimeType) {
if ((null == uri || Uri.EMPTY == uri) && (null == mimeType || mimeType.equals(""))) {
throw new IllegalArgumentException("Uri or the mimetype should be non null");
}
return canHandle(convertUriToPath(uri), mimeType);
}
canHandle(Uri uri , String mimeType)
基本相同,因为canHandle( String path, mimeType )
它是将 Uri 转换为 Path。
这是否意味着 Http Urls 不起作用?