1

I am developing an Android Application. I want to show web site with WebView. But i don't it. A blank/empty page is opening. The other web site showing but Why this is not showing? My code is below Please Help me, Thanks.

public class MainActivity extends ActionBarActivity{
    private WebView ourWebSite;
    private ProgressDialog pd;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);
        initViews();
        setProgressDialog();
    }

    private void initViews(){
        ourWebSite = (WebView) findViewById(R.id.ada_web_site);
        ourWebSite.getSettings().setJavaScriptEnabled(true);
        ourWebSite.setWebViewClient(new WebSiteWebViewClient());
        ourWebSite.loadUrl("http://fahrikayahantaksi.com/");
    }

    private void setProgressDialog(){
        pd = new ProgressDialog(MainActivity.this);
        pd.setMessage(getResources().getString(R.string.loading));
        pd.setProgressStyle(ProgressDialog.STYLE_SPINNER);
        pd.show();
    }

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

            if (!pd.isShowing()) {
                pd.show();
            }

            return true;
        }

        @Override
        public void onPageFinished(WebView view, String url) {
            System.out.println("on finish");
            if (pd.isShowing()) {
                pd.dismiss();
            }

        }

        @Override
        public void onReceivedSslError(WebView view, SslErrorHandler handler, SslError error) {
            handler.proceed(); // Ignore SSL certificate errors
        }
    }
}
Andev
  • 355
  • 3
  • 7
  • 16
  • So is the webview loading any url? or its just showing white for each url you enter – Andy Joyce May 22 '15 at 08:04
  • my url: http://fahrikayahantaksi.com/ – Andev May 22 '15 at 08:05
  • What i mean is, is the webview loading any url at all? or just your url is not loading. If nothing is loading in the webview make sure you have got internet permission in the manifest – Andy Joyce May 22 '15 at 08:17
  • i am deleting "fahrikayahantaksi.com". i am adding "radyoselam.com". The page is showing. But "fahrikayahantaksi.com" is not showing. A blank/empty page is opening. – Andev May 22 '15 at 08:21
  • did you checked my answer @MuhammedCobanoglu.. by using my answer i am able to load your "fahrikayahantaksi.com" website from app – King of Masses May 22 '15 at 10:25

2 Answers2

4

I think in your code you missed this suppressLint

@SuppressLint("SetJavaScriptEnabled")

Try to change your code like this.. in this way i am able to load your [page]

private WebView mWebview=null ;

 @SuppressLint("SetJavaScriptEnabled")
   @Override
public void onCreate(Bundle savedInstanceState) {

    super.onCreate(savedInstanceState);

    mWebview  = new WebView(this);

    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://fahrikayahantaksi.com/");
    setContentView(mWebview );

}

Don't forgot to add the Internet permission in your manifest !!

uses-permission android:name="android.permission.INTERNET" />
King of Masses
  • 18,405
  • 4
  • 60
  • 77
  • If this answer is helpful then accept it @MuhammedCobanoglu :) – King of Masses May 22 '15 at 11:06
  • i don't it. i am sorry. It is say "Vote Up requires 15 reputation" – Andev May 22 '15 at 12:03
  • not vote up accept it by tick mark @MuhammedCobanoglu :) Once you accept it you will get that 15 reps too :) – King of Masses May 22 '15 at 12:04
  • I have exactly same problem but above solution is not working, any other solution if this doesnt work? – Siddarth G Nov 17 '17 at 19:37
  • Do you have Android Internet permission in the manifest ? Check in the mobile browser are able to load the same webpage with that url. Post a new question with all details and Let me know, i vll help you further. @SiddarthG – King of Masses Nov 18 '17 at 13:49
  • @KingofMasses Hi i have posted the question https://stackoverflow.com/questions/47367382/android-webview-does-not-load-a-particular-website – Siddarth G Nov 18 '17 at 14:55
0
@SuppressLint("SetJavaScriptEnabled")
@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_webview);

    String url = getIntent().getStringExtra("url");
    webView = new WebView(this);
    webView.getSettings().setJavaScriptEnabled(true);
    final Activity activity = this;
    webView.setWebViewClient(new WebViewClient() {
        public void onReceivedError(WebView view, int errorCode, String description, String failingUrl) {
            Toast.makeText(activity, description, Toast.LENGTH_SHORT).show();
        }
    });
    webView.loadUrl("http://docs.google.com/viewer?embedded=true&url=" + url);
    setContentView(webView );
}

I used google docs to open pdf.