1

Why is it happening?

public class MainActivity extends Activity

    {

    WebView browser;

    @Override
    public void onCreate(Bundle icicle)
    {
        super.onCreate(icicle);
        setContentView(R.layout.activity_main);
        //browser.getSettings().setJavaScriptEnabled(true);

        browser = (WebView)findViewById(R.id.webkit);

        browser.loadUrl("www.microsoft.com");
    }
}

But when I run the Android HTML5 app I get this screen goo.gl/uDkj1

I also tried other possibilities such as http:// in front or end the address with a slash and so on.

A--C
  • 36,351
  • 10
  • 106
  • 92
user2077356
  • 37
  • 1
  • 4
  • maybe using url without http:// doesn't cause any error but always use http:// for your works. This is better way. – hakki Feb 16 '13 at 00:20

3 Answers3

3

I'm guessing that you forgot to set the internet permission:

<manifest [...]>
 [...]
 <uses-permission android:name="android.permission.INTERNET" />
</manifest>
Ahmad
  • 69,608
  • 17
  • 111
  • 137
  • Thank you, now it is opening the address in a browser instead of opening the page within the app itself. Why is that? – user2077356 Feb 16 '13 at 00:31
  • You need a WebViewClient to prevent that. Check [this](http://stackoverflow.com/a/13542994/1333975) out. – Ahmad Feb 16 '13 at 00:38
3

Make sure you have the Internet permission set in AndroidManifest.xml:

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

Edit:

browser.setWebViewClient(new WebViewClient() {
    @Override
    public boolean shouldOverrideUrlLoading(WebView view, String url) {         
        view.loadUrl(url);
        return true;
    }
});
Ljdawson
  • 12,091
  • 11
  • 45
  • 60
0

as the other answer said you must include the Internet permission, but please note that http://www.google.com differ of www.google.com so please include the protocol you are using in the URL.

Mohammad Ersan
  • 12,304
  • 8
  • 54
  • 77