我找到了以下Java代码,试图将其转换为Xamarin Android项目中使用的C#
webview.setWebChromeClient(new WebChromeClient(){
// Need to accept permissions to use the camera
@Override
public void onPermissionRequest(final PermissionRequest request) {
L.d("onPermissionRequest");
request.grant(request.getResources());
}
});
这在C#中将转换为什么?
最佳答案
C#不像Java那样支持内部类。您可以在正在使用的类中创建嵌套的WebChromeClient
子类:
public class CustomChromeClient : WebChromeClient
{
public override void OnPermissionRequest(PermissionRequest request)
{
request.Grant(request.GetResources());
}
}
接着:
webView.SetWebChromeClient(new CustomChromeClient());
回复:Nested Types (C# Programming Guide)