Android WebView doesnt load certain website - android

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

Related

Webpage not opening in webview

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.

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.

android webview unset default browser

I use the following to show a webpage in a webview
protected void onCreate(Bundle savedInstanceState) {
this.requestWindowFeature(Window.FEATURE_NO_TITLE);
this.getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, WindowManager.LayoutParams.FLAG_FULLSCREEN);
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_webview);
WebView webView = (WebView)findViewById(R.id.webView);
webView.setInitialScale(1);
webView.getSettings().setJavaScriptEnabled(true);
webView.getSettings().setLoadWithOverviewMode(true);
webView.getSettings().setUseWideViewPort(true);
webView.setClickable(true);
webView.setFocusableInTouchMode(true);
webView.getSettings().setJavaScriptEnabled(true);
webView.setScrollBarStyle(WebView.SCROLLBARS_OUTSIDE_OVERLAY);
webView.setScrollbarFadingEnabled(false);
WebSettings webSettings = webView.getSettings();
webSettings.setJavaScriptEnabled(true);
webSettings.setPluginState(WebSettings.PluginState.ON);
webSettings.setSupportZoom(true);
webSettings.setBuiltInZoomControls(true);
webView.loadUrl("http://www.bbc.co.uk");
}
It works perfect and even has pinch and zoom however When i click to go to another webpage via a link it opens it in the default browser instead of the webview
How to i achieve this. I have read many articles on this but cant understand where i need to insert the commands
Any help appreciated
Mark
thanks very much for the link above the following works perfect
myWebView.loadUrl("http://someurl.com");
myWebView.setWebViewClient(new WebViewClient() {
public boolean shouldOverrideUrlLoading(WebView viewx, String urlx) {
viewx.loadUrl(urlx);
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;
}
});

Android WebView - code that can display and play a podcast can't play a YouTube video

I have this code which works to display a WebView and use it:
WebView webview = null;
#Override
public void onCreate(Bundle savedInstanceState)
{
//setTheme(R.style.Theme_Sherlock_Light);
super.onCreate(savedInstanceState);
//setContentView(R.layout.podcasts);
webview = new WebView(this);
webview.getSettings().setAppCacheEnabled(false);
webview.getSettings().setJavaScriptEnabled(true);
webview.setInitialScale(1);
webview.getSettings().setPluginState(PluginState.ON);
webview.setWebViewClient(new WebViewClient() {
#Override
public boolean shouldOverrideUrlLoading(WebView view, String url) {
view.loadUrl(url);
return true;
}
});
//webSettings.setBuiltInZoomControls(true);
WebSettings webSettings = webview.getSettings();
webSettings.setJavaScriptEnabled(true);
webSettings.setBuiltInZoomControls(true);
//webSettings.getMediaPlaybackRequiresUserGesture();
webSettings.setAllowContentAccess(true);
webSettings.setEnableSmoothTransition(true);
webSettings.setLoadsImagesAutomatically(true);
webSettings.setLoadWithOverviewMode(true);
webSettings.setSupportZoom(true);
webSettings.setUseWideViewPort(true);
setContentView(webview);
webview.loadUrl("url_to_go_to");
But when I try to use this code to point to a YouTube channel, it just shows a blank screen.
Any idea why that would happen?
Thanks!
In order to get HTML5 videos to show up you need to enable the following things in the WebView:
WebView view;
... //initialize WebView
WebSettings webViewSettings = view.getSettings();
view.setWebChromeClient(new WebChromeClient(){}); //just added this
webViewSettings.setDomStorageEnabled(true);
webViewSettings.setAppCacheEnabled(true);
webViewSettings.setAppCachePath(getApplicationContext().getFilesDir().getAbsolutePath() + "/cache");
webViewSettings.setDatabaseEnabled(true);
webViewSettings.setDatabasePath(getApplicationContext().getFilesDir().getAbsolutePath() + "/databases");
You also need to put android:hardwareAccelerated="true" in your AndroidManifest. Otherwise, HTML5 stuff like YouTube videos won't work.

Categories

Resources