Android WebView not loading URL

String picture String · Apr 25, 2013 · Viewed 128.2k times · Source

I want to load the URL in WebView

I have used the following Code:

webView = (WebView) findViewById(R.id.webview1);
webView.setWebViewClient(new HostsWebClient());
webView.getSettings().setPluginState(PluginState.ON);
webView.getSettings().setJavaScriptEnabled(true);
webView.getSettings().setJavaScriptCanOpenWindowsAutomatically(false);
webView.getSettings().setPluginsEnabled(true);
webView.getSettings().setSupportMultipleWindows(false);
webView.getSettings().setSupportZoom(false);
webView.setVerticalScrollBarEnabled(false);
webView.setHorizontalScrollBarEnabled(false);

webView.loadUrl(URL);

But when I execute it, I'm not able to load the url. I am getting web page not available.

Could anyone help?

Answer

itsrajesh4uguys picture itsrajesh4uguys · Apr 25, 2013

Did you added the internet permission in your manifest file ? if not add the following line.

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

hope this will help you.

EDIT

Use the below lines.


    public class WebViewDemo extends Activity {


        private WebView webView;


        Activity activity ;
        private ProgressDialog progDailog; 

        @SuppressLint("NewApi")
        @Override
        public void onCreate(Bundle savedInstanceState) {
            super.onCreate(savedInstanceState);
            setContentView(R.layout.main);

            activity = this;

            progDailog = ProgressDialog.show(activity, "Loading","Please wait...", true);
            progDailog.setCancelable(false);



           webView = (WebView) findViewById(R.id.webview_compontent);



           webView.getSettings().setJavaScriptEnabled(true);     
           webView.getSettings().setLoadWithOverviewMode(true);
           webView.getSettings().setUseWideViewPort(true);        
            webView.setWebViewClient(new WebViewClient(){

                @Override
                public boolean shouldOverrideUrlLoading(WebView view, String url) {
                    progDailog.show();
                    view.loadUrl(url);

                    return true;                
                }
                @Override
                public void onPageFinished(WebView view, final String url) {
                    progDailog.dismiss();
                }
            });

            webView.loadUrl("http://www.teluguoneradio.com/rssHostDescr.php?hostId=147");

           }
    }