Issue
I reference this, I want open a new webView, when I meet window.open
. I tried hard code to open a Google page, this is my code
class MainActivity : AppCompatActivity() {
private var myWebView: WebView? = null
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContentView(R.layout.activity_main)
myWebView = findViewById(R.id.webview)
myWebView!!.settings.javaScriptEnabled = true
myWebView!!.settings.domStorageEnabled = true
myWebView!!.settings.setSupportMultipleWindows(true)
myWebView!!.settings.javaScriptCanOpenWindowsAutomatically = true
myWebView!!.webViewClient = object : WebViewClient() {
override fun shouldOverrideUrlLoading(view: WebView?, url: String?): Boolean {
view?.loadUrl(url)
return true
}
}
myWebView!!.webChromeClient = object : WebChromeClient() {
....
override fun onCreateWindow(
view: WebView,
dialog: Boolean,
userGesture: Boolean,
resultMsg: android.os.Message
): Boolean {
var cookieValues: HashMap<String, String> = _parseCookie(view.url)
var tokenData: HashMap<String, String> = HashMap()
val newWebView = WebView(view.context)
view.addView(newWebView)
newWebView.settings.javaScriptEnabled = true
newWebView.settings.setSupportZoom(true)
newWebView.settings.builtInZoomControls = true
newWebView.settings.setSupportMultipleWindows(true)
val transport = resultMsg.obj as WebView.WebViewTransport
transport.webView = newWebView
resultMsg.sendToTarget()
newWebView.webViewClient = object : WebViewClient(){
override fun shouldOverrideUrlLoading(
view: WebView, url: String
): Boolean {
view.loadUrl("https://www.google.com")
return true
}
}
return true
}
}
myWebView!!.loadUrl("http://www.example.com")
}
....
}
It's work, but the new webView size didn't full scree, and I click the search input, this app closed, I got this message.
E/EGL_emulation: tid 8491: eglSurfaceAttrib(1354): error 0x3009 (EGL_BAD_MATCH)
W/OpenGLRenderer: Failed to set EGL_SWAP_BEHAVIOR on surface 0xd623bbc0, error=EGL_BAD_MATCH
W/cr_AwAutofillManager: Application attempted to call on a destroyed AwAutofillManager
java.lang.Throwable
at org.chromium.android_webview.AwAutofillManager.checkAndWarnIfDestroyed(AwAutofillManager.java:18)
at org.chromium.android_webview.AwAutofillProvider.startAutofillSession(AwAutofillProvider.java:98)
at org.chromium.base.SystemMessageHandler.nativeDoRunLoopOnce(Native Method)
at org.chromium.base.SystemMessageHandler.handleMessage(SystemMessageHandler.java:9)
at android.os.Handler.dispatchMessage(Handler.java:106)
at android.os.Looper.loop(Looper.java:193)
at android.app.ActivityThread.main(ActivityThread.java:6680)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:493)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:858)
W/cr_AwAutofillManager: Application attempted to call on a destroyed AwAutofillManager
java.lang.Throwable
at org.chromium.android_webview.AwAutofillManager.checkAndWarnIfDestroyed(AwAutofillManager.java:18)
at org.chromium.android_webview.AwAutofillManager.notifyVirtualViewEntered(AwAutofillManager.java:11)
at org.chromium.android_webview.AwAutofillProvider.startAutofillSession(AwAutofillProvider.java:103)
at org.chromium.base.SystemMessageHandler.nativeDoRunLoopOnce(Native Method)
at org.chromium.base.SystemMessageHandler.handleMessage(SystemMessageHandler.java:9)
at android.os.Handler.dispatchMessage(Handler.java:106)
at android.os.Looper.loop(Looper.java:193)
at android.app.ActivityThread.main(ActivityThread.java:6680)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:493)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:858)
This is my activity_main.xml
<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.ConstraintLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".MainActivity">
<WebView
android:id="@+id/webview"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:layout_editor_absoluteX="8dp"
tools:layout_editor_absoluteY="8dp" />
</androidx.constraintlayout.widget.ConstraintLayout>
How can I fix it? Thanks your help.
Solution
This is work for me, I need set layoutParams
to new webView. So I reuse the original view layout.
newWebView.layoutParams = view.layoutParams
Answered By - lighter
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.