Android Webview is not showing pop up window - android

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());

Related

How to remove or disable WebView header?

I'm trying to remove the webview header, I've tried a number of possible solutions but to no avail.
One of my attempts:
android:theme="#android:style/Theme.NoTitleBar"
I'm loading the webview using this code:
setContentView(R.layout.activity_websitenew1);
WebView myWebView = (WebView) findViewById(R.id.webView1);
myWebView.loadUrl("http://www.domain.com");
myWebView .setWebViewClient(new WebViewClient());
myWebView.getSettings().setJavaScriptEnabled(true);
What is happening in your case is that the URL is being handled by Android which is choosing the handler for you. This handler is the system's browser application. What you want is for control to stay within your app.
You can do this in code as follows:
WebView myWebView = (WebView) findViewById(R.id.webView1);
myWebView.setWebViewClient(new WebViewClient() {
#Override
public boolean shouldOverrideUrlLoading(WebView view, String url) {
view.loadUrl(url);
return true;
}
});
myWebView.getSettings().setJavaScriptEnabled(true);
myWebView.loadUrl("http://www.domain.com");
See http://developer.android.com/reference/android/webkit/WebViewClient.html#shouldOverrideUrlLoading(android.webkit.WebView,%20java.lang.String) for details.

Click hyperlink on WebView launch other browser app

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;
}
});

Android webview navigate in app not open browser [duplicate]

I have a webview in my android app, but when someone navigates around the site, it opens in a new window, i want it to stay inside the webview.. is there a way to do this easily? Here is the code in my activity:
super.onCreate(savedInstanceState);
setContentView(R.layout.shop);
WebView webview;
webview = (WebView) findViewById(R.id.webview);
webview.getSettings().setJavaScriptEnabled(true);
webview.loadUrl("http://www.google.co.uk");
You'll have to create a WebViewClient:
public class myWebViewClient extends WebViewClient {
#Override
public boolean shouldOverrideUrlLoading(WebView view, String url) {
view.loadUrl(url);
return true;
}
}
And then set it to your WebView like this:
webview.setWebViewClient(new myWebViewClient());
Or you can just do that, without creating a new class:
myWebView.setWebViewClient(new WebViewClient());
It works for me.
webview.setWebViewClient(new WebViewClient());
If you want to customize then you should override shouldOverrideUrlLoading (WebView view, String url). but it's deprecated in API 24. You can use public boolean shouldOverrideUrlLoading (WebView view,WebResourceRequest request). actually both of them needs to return false.
Android WebView Example

surfing all website and all links opens in same webview

when I create webview application to view any website on same webview not browser it works fine but when I click on any link in that website it opens in browser ? how to load all internal links/pages/sections when user click on them at same webview ?
Java version:
You only need to set a WebViewClient for your WebView and then all links will be opened it the same WebView:
webView.setWebViewClient(new WebViewClient());
private class myCustomWebViewClient extends WebViewClient {
#Override
public boolean shouldOverrideUrlLoading(WebView view, String url) {
//here load the url in your webview
webview.loadUrl(url);
return true;
}
And this for set in your webview
webView.setWebViewClient(new myCustomWebViewClient());
Kotlin version.
webView.webViewClient = WebViewClient()
You should add a webViewClient of your own.
WebView myWebView = (WebView) findViewById(R.id.webview);
myWebView.setWebViewClient(new MyWebViewClient());
in the webViewClient you can override the shouldOverrideUrlLoading() method to be like:
#Override
public boolean shouldOverrideUrlLoading(WebView view, String url) {
if (Uri.parse(url).getHost().equals("www.example.com")) {
// This is my web site, so do not override; let my WebView load the page
return false;
}
// Otherwise, the link is not for a page on my site, so launch another Activity that handles URLs
Intent intent = new Intent(Intent.ACTION_VIEW, Uri.parse(url));
startActivity(intent);
return true;
}
I hope you find it helpful.

Images from Flickr not seen in Android app

I am loading a Flickr URL to a webView to load in the following way
WebView webview = (WebView) findViewById(R.id.flickrWebView);
webview.getSettings().setJavaScriptEnabled(true);
webview.setWebViewClient(new WebViewClient(){
#Override
public boolean shouldOverrideUrlLoading(WebView view, String url) {
view.loadUrl(url);
return true;
}
});
webview.loadUrl(flickrURL);
The page gets loaded smoothly without any problem. But when I click on image/picture from Flickr page to zoom and start slideshow, the images/pictures are not loaded and only a black screen is loaded. What am I missing?
I solved the issue by adding the following setting to webview.
webview.getSettings().setJavaScriptEnabled(true);
webview.getSettings().setDomStorageEnabled(true);
WebViewClient webclient = new WebViewClient();
webview.setWebViewClient(webclient);
webview.loadUrl(flickrURL);

Categories

Resources