如何在 webview 中启用受保护的内容? [英] How to Enable protected content in a webview?
本文介绍了如何在 webview 中启用受保护的内容?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
在 Chrome 浏览器中,可以选择播放受保护的内容.如何在 android 的 webview 中启用相同的功能?
In chrome browser, there is an option to play protected content. How do I enable the same in webview in android?
我尝试了一种名为 allowContentAccess()
的方法,但它不起作用.
I have tried a method called allowContentAccess()
but that does not work.
请帮忙
推荐答案
要允许 webview 播放 DRM 内容,您必须授予 webview RESOURCE_PROTECTED_MEDIA_ID 权限.
To allow a webview to play a DRM content you have to grant RESOURCE_PROTECTED_MEDIA_ID permission to the webview.
您可以通过覆盖 WebChromeClient#onPermissionRequest 来实现
You can do it by override of WebChromeClient#onPermissionRequest
作为示例:
@Override
public void onPermissionRequest(PermissionRequest request) {
String[] resources = request.getResources();
for (int i = 0; i < resources.length; i++) {
if (PermissionRequest.RESOURCE_PROTECTED_MEDIA_ID.equals(resources[i])) {
request.grant(resources);
return;
}
}
super.onPermissionRequest(request);
}
这篇关于如何在 webview 中启用受保护的内容?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文