Bryan
Bryan

Reputation: 275

webview not loading correctly in application

I have an application that has a tab widget in it. One of the tabs loads a webview for me and it is not loading correctly. when i load the same address in just my phone browser it loads fine. here is the code for the webview i'm using

import android.app.Activity;
import android.os.Bundle;
import android.webkit.WebView;

public class Sermons extends Activity {
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    WebView webview = new WebView(this);
    setContentView(webview);

 // Simplest usage: note that an exception will NOT be thrown
    // if there is an error loading this page (see below).
    webview.loadUrl("http://canyonculberts.com/ucc/?page_id=93");
    webview.getSettings().setBuiltInZoomControls(true);
    webview.setInitialScale(1);
    webview.getSettings().setAppCacheEnabled(false);

}
}

anyone have any thoughts on what i can do different on this to make it work correctly? Thank you for any help

Upvotes: 0

Views: 4801

Answers (4)

hsul4n
hsul4n

Reputation: 523

Actually, After I tried many times .. I Solved it by adding this line.

mWebView.getSettings().setUserAgentString("Mozilla/5.0 (Linux; Android 6.0; Nexus 5 Build/MRA58N) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/70.0.3538.77 Mobile Safari/537.36");

Upvotes: -1

Cytown
Cytown

Reputation: 1547

First, you need android.permission.INTERNET permission.

Second, you may need setJavaScriptEnabled(true) to settings, and do loadUrl at the very last.

webview.getSettings().setBuiltInZoomControls(true);
webview.setInitialScale(1);
webview.getSettings().setAppCacheEnabled(false);
webview.getSettings().setJavaScriptEnabled(true);
webview.loadUrl("http://canyonculberts.com/ucc/?page_id=93");

Upvotes: 1

user1213202
user1213202

Reputation: 1305

Try with this..

            webView = (WebView) findViewById(R.id.webview);
        webView.getSettings().setJavaScriptEnabled(true);
        webView.setWebViewClient(new WebViewClient());
    webView.loadUrl("http://www.google.com");

Upvotes: 0

Newts
Newts

Reputation: 1372

You have to try this code It wiil help you!

 WebView webview = new WebView(this);
    setContentView(webview);

         WebSettings webSettings = web.getSettings();

         webSettings.setJavaScriptEnabled(true);

         webview.loadUrl("url");

Upvotes: 1

Related Questions