0

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

Bryan
  • 275
  • 1
  • 8
  • 24

4 Answers4

1

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");
Cytown
  • 1,539
  • 9
  • 7
  • 1
    ok i have internet permission done already, where do i do the setJavaScriptEnable at is it in the code i have here or where? – Bryan Feb 24 '12 at 04:17
  • 1
    WOW that worked great and worked perfectly THANK YOU FOR THAT VERY MUCH – Bryan Feb 26 '12 at 00:58
1

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");
Newts
  • 1,354
  • 14
  • 23
  • gives me an error on the (R.id.web) any suggestions. it says web cannot be resolved – Bryan Feb 24 '12 at 04:21
  • @Bryan see edited answer first. I think its solve there was variable problem – Newts Feb 24 '12 at 04:27
  • I think we are on the right path but now my app is force closing on launch and this is all i've changed, any ideas why – Bryan Feb 24 '12 at 04:54
  • its giving a fatal error on the main activity that loads the tabhost now, not sure how its related to this though – Bryan Feb 24 '12 at 05:07
0

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");
hsul4n
  • 491
  • 7
  • 15
0

Try with this..

            webView = (WebView) findViewById(R.id.webview);
        webView.getSettings().setJavaScriptEnabled(true);
        webView.setWebViewClient(new WebViewClient());
    webView.loadUrl("http://www.google.com");
user1213202
  • 1,305
  • 11
  • 23