2

I ma newbie to android and making a demo on webview,I have a test url which is working fine with my laptop browser and i have set it in my webview,but it is not loading and it says "Webpage not available",Please help me to figure it out,need help,

code

package namo.jims.com.webviewapp;

import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.Menu;
import android.webkit.WebView;
import android.webkit.WebViewClient;

public class MainActivity extends AppCompatActivity {
    WebView webview;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        webview= (WebView)findViewById(R.id.webview);
        webview.setWebViewClient(new MyBrowser());
        webview.loadUrl("http://rchitecture.in/app1/");
        webview.getSettings().setLoadWithOverviewMode(true);
        webview.getSettings().setUseWideViewPort(true);
        webview.getSettings().setJavaScriptEnabled(false);
        webview.getSettings().setAllowFileAccess(true);
        webview.getSettings().setAllowContentAccess(true);
        webview.setScrollbarFadingEnabled(false);

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

}
sulphuric Acid
  • 585
  • 6
  • 23

1 Answers1

1

You need to add the Internet Permission

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

You need to follow my answer here... Snapchat Url load issue

 WebSettings settings = webview.getSettings();
    settings.setJavaScriptEnabled(true);
    //ws.setJavaScriptEnabled(true);
    settings.setJavaScriptCanOpenWindowsAutomatically(true);
    webview.setScrollBarStyle(WebView.SCROLLBARS_OUTSIDE_OVERLAY);



 webview.setWebViewClient(new WebViewClient() {

        public boolean shouldOverrideUrlLoading(WebView view, String url) {


            if( url.startsWith("http:") || url.startsWith("https:") ) {
                return false;
            }
          //  Log.i(TAG, "Processing webview url click..."+url);
         //  view.loadUrl(url);

            return true;
        }


        public void onPageFinished(WebView view, String url) {
            Log.e(TAG, "Finished loading URL: " + url);

        }


        public void onReceivedError(WebView view, int errorCode, String description, String failingUrl) {



        }
    });

    webview.loadUrl("http://rchitecture.in/app1/");
Community
  • 1
  • 1
Arjun saini
  • 4,223
  • 3
  • 23
  • 51