0

I have a WebView trying to load a WebPage like this:

public void onCreate(Bundle savedInstanceState)
{
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_web);
    wv=(WebView)findViewById(R.id.webview);
    WebSettings ws=wv.getSettings();
    ws.setJavaScriptEnabled(true);
    wv.loadUrl("http://pro39.blutechnologies.com/crimes.aspx");
}

I have added the internet permission to the manifest

<uses-permission android:name="android.permission.INTERNET"/>

However the WebView is blank,it neither throws an error nor loads the web-page.How do I load webpages like this,I have only tried loading local html files before and I would like to know if I have to do something different.

vamsiampolu
  • 6,328
  • 19
  • 82
  • 183

2 Answers2

1

Try like this way:

 mWebView.loadUrl("http://pro39.blutechnologies.com/crimes.aspx");  
 mWebView.setWebViewClient(new HelloWebViewClient());

  private class HelloWebViewClient extends WebViewClient {
  @Override
  public boolean shouldOverrideUrlLoading(WebView view, String url) {
    view.loadUrl(url);
    return true;
 }

Use this code .shouldOverrideUrlLoading() not use compulsary.use this code and please reply me this code work or not

M D
  • 47,665
  • 9
  • 93
  • 114
  • It works,was the page redirecting somewhere else...or is this nessecary whenever I use a url,will accept answer as soon as I can. – vamsiampolu Feb 20 '14 at 06:21
  • just return false; from shouldOverrideUrlLoading. Calling view.loadUrl will result in problems if the page has an iframe with a custom scheme. – marcin.kosiba Feb 20 '14 at 10:11
  • @marcin.kosiba i dont know much more about iframe. but it's working in my case. – M D Feb 20 '14 at 10:14
  • yes, whether you hit the problem or not depends on the HTML you're trying to load. It will also work if you just return false; try it out ;) – marcin.kosiba Feb 20 '14 at 10:17
  • @marcin.kosiba let me check. wait – M D Feb 20 '14 at 10:18
  • Also, just to prove my point - load http://jsbin.com/gupug/1/quiet using your current shouldOverrideUrlLoading implementation. – marcin.kosiba Feb 20 '14 at 10:35
  • @marcin.kosiba you are absolutely right.it's working with return false value. it's strange. – M D Feb 20 '14 at 11:17
0

Try below code.

public class Main extends Activity {
    private WebView mWebview ;
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_web);

        mWebview = (WebView)findViewById(R.id.webview);
        mWebview.getSettings().setJavaScriptEnabled(true); // enable javascript

        final Activity activity = this;

        mWebview.setWebViewClient(new WebViewClient() {
            public void onReceivedError(WebView view, int errorCode, String description, String failingUrl) {
                Toast.makeText(activity, description, Toast.LENGTH_SHORT).show();
            }
        });

        mWebview .loadUrl("http://pro39.blutechnologies.com/crimes.aspx");
        setContentView(mWebview );
    }
}
InnocentKiller
  • 5,234
  • 7
  • 36
  • 84