所以我有一个要显示的Web视图。 Webview摄像机内部的访问权限需要授予用户。
因此,使用chrome自定义标签可以解决此问题,而chrome本身将向用户征求使用相机的许可,就像在网络上一样。
现在我的问题是,如果未安装chrome,我想处理回退。
所以我做了一个备用的webview。问题是当涉及到webviewClient()类(不是WebChromeClient()类)时,我不知道如何授予用户权限
如果我们检查WebChromeClient,我们会看到它有一个方法可以重写以处理名为onPermissionRequest(...)的请求
但是我看不到webviewclient的任何内容。这是我到目前为止所拥有的:
class CustomFallBackWebViewActivity CustomTabsHelper.CustomTabFallback {
override fun openUri(context: Context?, uri: Uri?) {
val i = Intent(context, CustomFallBackWebViewActivity::class.java)
i.putExtra(WebViewActivity.EXTRA_URL, uri.toString())
context?.startActivity(i)
}
@Inject
lateinit var permissionManager: PermissionManager
override fun onCreate(savedInstanceState: Bundle?) {
(applicationContext as MyApplication).appComponent.inject(this)
super.onCreate(savedInstanceState)
setContentView(R.layout.activity_fallback_webview)
val url = intent.extras?.getString(WebViewActivity.EXTRA_URL)
url?.let { showWebView(url) }
}
override fun showWebView(url: String) {
webView.webChromeClient = FallBackWebChromeClient()
webView.webViewClient = WebViewClient() //WHAT SHOULD I OVERRIDE HERE TO perform the permission handling incase chrome is not stalled i assume this is used
webView.loadUrl(url)
webView.settings.javaScriptEnabled = true
}
//i assume the below class gets called only if chrome is installed , right ?
inner class FallBackWebChromeClient : WebChromeClient() {
//this is NEVER called when using webViewClient()...
override fun onPermissionRequest(request: PermissionRequest?) {
//super.onPermissionRequest(request)
permissionManager.requestCameraPermission(this@CustomFallBackWebViewActivity) //show the permission screen myself (is there any other way ?)
}
override fun onPermissionRequestCanceled(request: PermissionRequest?) {
super.onPermissionRequestCanceled(request)
}
}
}
如果真的很重要,这就是我的使用方式:
CustomTabsIntent customTabsIntent = new CustomTabsIntent.Builder()
.addDefaultShareMenuItem()
.setToolbarColor(this.getResources().getColor(R.color.white))
.enableUrlBarHiding()
.setShowTitle(true)
.build();
// This is optional but recommended, pre-warming info
CustomTabsHelper.addKeepAliveExtra(getActivity(), customTabsIntent.intent);
CustomTabsHelper.openCustomTab(getActivity(), customTabsIntent,
Uri.parse(url),
new CustomFallBackWebViewActivity());