I'm creating an android application which opens a HTML page in Webview and after clicking the button on HTML page it opens up pop-up kind webview like below. I want to Toast URL loading in popup window. Can someone help on this?
I'm adding the screenshots how the webpage is displayed on desktop/laptops and how on Android application for reference.
This is how Page is displayed on Chrome Desktop
This is how Page is displayed on Android Application Webview
I have tried the following code to handle the second window :-
WebView webview = findViewById(R.id.webview);
WebSettings webSettings = webview.getSettings();
webview.getSettings().setLoadWithOverviewMode(true);
webview.getSettings().setBuiltInZoomControls(true);
webview.getSettings().setJavaScriptEnabled(true);
webview.getSettings().setSupportMultipleWindows(true);
webview.getSettings().setDisplayZoomControls(true);
webview.getSettings().setUseWideViewPort(true);
if (android.os.Build.VERSION.SDK_INT >= 21) {
CookieManager.getInstance().setAcceptThirdPartyCookies(webview, true);
} else {
CookieManager.getInstance().setAcceptCookie(true);
}
webview.setWebChromeClient(new WebChromeClient() {
#Override
public boolean onCreateWindow(WebView view, boolean isDialog,
boolean isUserGesture, Message resultMsg) {
WebView newWebView = new WebView(getApplicationContext());
newWebView.getSettings().setJavaScriptEnabled(true);
newWebView.getSettings().setSupportZoom(true);
newWebView.getSettings().setBuiltInZoomControls(true);
newWebView.getSettings().setPluginState(WebSettings.PluginState.ON);
newWebView.getSettings().setSupportMultipleWindows(true);
view.addView(newWebView);
WebView.WebViewTransport transport = (WebView.WebViewTransport) resultMsg.obj;
transport.setWebView(newWebView);
resultMsg.sendToTarget();
newWebView.setWebChromeClient(new WebChromeClient() {
#Override
public void onPageFinished(WebView view, String url) {
Toast.makeText(getApplicationContext(),"URL"+url,Toast.LENGTH_SHORT);
}
});
newWebView.loadUrl(url);
return true;
}
});
`
Related
mWebView = (WebView) findViewById(R.id.webview_m);
progressBar = (ProgressBar) findViewById(R.id.progressBar1);
WebSettings webSettings = mWebView.getSettings();
webSettings.setJavaScriptEnabled(true);
mWebView.setWebViewClient(new WebViewClient() {
#Override
public boolean shouldOverrideUrlLoading(WebView view, String url) {
return false;
}
});
mWebView.loadUrl(url);
above code work fine when loading website like :
google.com
html5test.com
blogspot
and other normal website, but when i try to load url like:
http://sipp.pn-sanggau.go.id/
http://sipp.pn-bandung.go.id/
it doesnt work (not load in my activity), why does this happen?
Add below lines in your code.
webView.setWebChromeClient(new WebChromeClient() );
webView.getSettings().setPluginState(PluginState.ON);
I need in-app browser to hit a URL and authenticate a user,that website pop up a window (on all other browser), but it is not showing pop up on the WebView.
This is my code
webView.getSettings().setJavaScriptEnabled(true);
webView.getSettings().setJavaScriptCanOpenWindowsAutomatically(true);
webView.setWebViewClient(new WebViewClient() {
#Override
public boolean shouldOverrideUrlLoading(WebView view, String url) {
webView.loadUrl(url);
return true;
}
});
As stated in this issue at Google Code, you should use WebChromeClient within your webview.
WebView wv=new WebView(this);
wv.setWebChromeClient(new WebChromeClient());
I use below code to load URLPath in WebView:
WebView webView = (WebView)findViewById(R.id.webview);
String myURL = URLPath;
WebSettings websettings = webView.getSettings();
websettings.setSupportZoom(true);
websettings.setBuiltInZoomControls(true);
websettings.setJavaScriptEnabled(true);
webView.setWebViewClient(new WebViewClient());
webView.loadUrl(myURL);
The url page contain hyperlink.
I want to launch other browser app(such as chrome) while click hyperlink.
How can I do it?
Use this code
webView.setWebViewClient(new WebViewClient(){
#Override
public boolean shouldOverrideUrlLoading(WebView view, String url){
if(url.equals("http:\\your.url")
view.loadUrl(url);
else
// Do something here to open link in google chrome or some external browser
return true;
}
});
In recents, i had a problem with android webview i wanted to play youtube embed video center of the screen but webview had showed me black blank area in right side of video. Now i need to open documents by using Google docs but i have same problem in documents like:
Here is my webview codes:
WebView mWebView = (WebView)findViewById(R.id.webView1);
if (Build.VERSION.SDK_INT < 8) {
mWebView.getSettings().setPluginsEnabled(true);
} else {
mWebView.getSettings().setPluginState(PluginState.ON);
}
mWebView.getSettings().setUseWideViewPort(true);
mWebView.getSettings().setJavaScriptEnabled(true);
mWebView.getSettings().setLayoutAlgorithm(LayoutAlgorithm.NORMAL);
mWebView.setHorizontalScrollBarEnabled(false);
mWebView.setVerticalScrollBarEnabled(false);
mWebView.getSettings().setDefaultZoom(ZoomDensity.CLOSE);
mWebView.setInitialScale(-20);
mWebView.setWebChromeClient(new WebChromeClient());
mWebView.setWebViewClient(new WebViewClient() {
public boolean shouldOverrideUrlLoading(WebView view, String url) {
view.loadUrl(url);
return false;
}
});
//mWebView.loadUrl(" http://docs.google.com/viewer?url=http%3A%2F%2Fresearch.google.com%2Farchive%2Fbigtable-osdi06.pdf");
String pdf = "http://www.projectcounter.org/SSPJune_2007.ppt";
mWebView.loadUrl("http://docs.google.com/gview?embedded=true&url=" + pdf);
I'm building my app on webview service and trying to open new url in another window (neither in default system browser nor in same webview). I set up my own WebViewClient and WebChromeClient like below,
public class MyWebViewClient extends WebViewClient {
#Override
public boolean shouldOverrideUrlLoading (WebView view, String url) {
view.loadUrl(url);
return true;
}
}
public class MyWebChromeClient extends WebChromeClient {
#Override
public boolean onCreateWindow (WebView view, boolean isDialog, boolean isUserGesture, Message resultMsg) {
WebView childView = new WebView(view.getContext());
final WebSettings settings = childView.getSettings();
settings.setJavaScriptEnabled(true);
childView.setWebChromeClient(this);
childView.getSettings().setJavaScriptCanOpenWindowsAutomatically(true);
WebView.WebViewTransport transport = (WebView.WebViewTransport) resultMsg.obj;
transport.setWebView(childView);
resultMsg.sendToTarget();
Log.d(LOG_TAG, "onCreateWindow"); // never log
return true;
}
}
I also definitely had my webview setSupportMultipleWindows to true.
However, onCreateWindow never got called. Is there anything I missed?
Thanks in advance.
Did you tell the "parent" webview that multiple windows are allowed?
WebView parentWebview = (WebView) findViewById(R.id.parent_webview);
// ...
parentWebview.getSettings().setSupportMultipleWindows(true);
That's the most common mistake I've seen.
add this line to code to invoke onCreateWindow()
webView.getSettings().setSupportMultipleWindows(true);
Without the full code its hard to say why OnCreateWindow() isn't being called. In your activity OnCreate() method do you have code similar to the following?
// Get the main web viewer
mWebView = (WebView) findViewById(R.id.webViewer);
// Enable Javascript
WebSettings webSettings = mWebView.getSettings();
webSettings.setJavaScriptEnabled(true);
// Set WebViewClient and WebChromClient
mWebView.setWebViewClient(new MyWebViewClient());
mWebView.setWebChromeClient(new MyWebChromeClient());
Also, what code are you using in which you think the OnCreateWindow() should be called?