delight-im / Android-AdvancedWebView

Enhanced WebView component for Android that works as intended out of the box
MIT License
2.39k stars 574 forks source link

multi-window support question #180

Closed ubergeekzone closed 5 years ago

ubergeekzone commented 6 years ago

I took a look at the multi-window sample code you provided and i am confused a little bit,

AdvancedWebView newWebView = new AdvancedWebView(MyNewActivity.this);
// myParentLayout.addView(newWebView, LayoutParams.MATCH_PARENT, LayoutParams.MATCH_PARENT);
WebView.WebViewTransport transport = (WebView.WebViewTransport) resultMsg.obj;
transport.setWebView(newWebView);
resultMsg.sendToTarget();

Could you explain how to use multi window support a little more?

ocram commented 6 years ago

First, you should read the official documentation on Android’s WebChromeClient and its method onCreateWindow, which you should implement as you’ve seen and which should be called by the OS.

Next, try logging something inside that onCreateWindow callback to see if it’s actually called when you want to open a new window.

The official documentation on that method reads as follows:

Request the host application to create a new window. If the host application chooses to honor this request, it should return true from this method, create a new WebView to host the window, insert it into the View system and send the supplied resultMsg message to its target with the new WebView as an argument. If the host application chooses not to honor the request, it should return false from this method. The default implementation of this method does nothing and hence returns false. […] resultMsg | Message | The message to send when once a new WebView has been created. resultMsg.obj is a WebView.WebViewTransport object. This should be used to transport the new WebView, by calling WebView.WebViewTransport.setWebView(WebView).

So that explains all but the first two lines inside the callback, right? And in the first two lines, you should just create a new WebView and insert it into the hierarchy of views. Does that make sense? You don’t have to use the lines exactly as shown. Feel free to adjust them so that you can create your WebView and insert the view. Thus, instead of MyNewActivity.this, you can just use this from your current Activity, e.g. MyActivity.this.

Does that help?