Webpage not opening in webview - android

My Code:
String myURL = "https://google.com/";
myWebView = (WebView) findViewById(R.id.webV) ;
WebSettings mywebS= myWebView.getSettings();
mywebS.setJavaScriptEnabled(true);
myWebView.loadUrl(myURL);
it is always asking me permission to open in the system browser.

You must have to add permisssion for internet in manifest file
myWebView.loadUrl("https://www.google.com/");
myWebView.getSettings().setJavaScriptEnabled(true);
myWebView.setWebViewClient(new WebViewClient() {
#Override
public boolean shouldOverrideUrlLoading(WebView view, WebResourceRequest request) {
myWebView.loadUrl(request.getUrl().toString());
return false;
}
});
here setting up a webview client is required

The Easiest way is:
myWebView.setWebViewClient(new WebViewClient());
Add this line.

Related

Android WebView doesnt load certain website

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

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.

URL opened in browser instead of web view

I am using below code to open a link in web view -
mWebView = (WebView) findViewById(R.id.webview);
mWebView.setVisibility(View.VISIBLE);
mWebView.getSettings().setAllowFileAccess(true);
mWebView.getSettings().setJavaScriptEnabled(true);
mWebView.getSettings().setPluginState(PluginState.ON);
mWebView.getSettings().setBuiltInZoomControls(true);
mWebView.loadUrl(link);
But it opens the link in browser.
I want that the url should only open in my web view. Is there any mistake in the code. Please suggest.
Thanks in advance.
You need to override WebViewClient of your webview and set it. Like it is mentioned in one of the comments on your question.
mWebView.setWebViewClient(new WebViewClient());
And google first, you may not need to post the question.
You should init WebViewClient: mWebView.setWebViewClient(new WebViewClient())
This might help:
webview.setWebViewClient(new WebViewClient() {
#Override
public boolean shouldOverrideUrlLoading(WebView view, String url) {
//set URL Here
return false;
}
}

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

Why Android WebChromeClient's onCreateWindow method never got called?

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?

Categories

Resources