Skip to content Skip to sidebar Skip to footer

URL Not Loading In Webview But Loaded In Browser In Android?

Some type of Urls are not loading in my app in Webview but it can be loaded in device browser. Following is the example Url which is not working in my code- 'http://apps.takeyourap

Solution 1:

Create WebViewClient and load url like

 public class myWebClient extends WebViewClient {
    @Override
            public boolean shouldOverrideUrlLoading(WebView view, String url) {
                // TODO Auto-generated method stub
                view.loadUrl(url);
                return true;
            }
}

And setWebViewClient like:

    webView.setWebViewClient(new myWebClient());
    webView.getSettings().setJavaScriptEnabled(true);
    webView.loadUrl("http://apps.takeyourapp.com/testApp/staging/index.html");

And also add INTERNET permission into manifest.xml

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

Solution 2:

Try this solution.

public class Main extends Activity {

    private WebView mWebview ;

    @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://apps.takeyourapp.com/testApp/staging/index.html");
        setContentView(mWebview );

    }

}

Post a Comment for "URL Not Loading In Webview But Loaded In Browser In Android?"