Reputation: 51
I'm trying to display a web page using a WebView. I'm not using pretty much the same code as the WebView example:
webview = (WebView)findViewById( R.id.webview );
webview.getSettings().setJavaScriptEnabled(true);
webview.loadUrl( url );
webview.setWebViewClient( new WebViewClient() {
public boolean shouldOverrideUrlLoading(WebView view, String url) {
view.loadUrl(url);
return true;
}
}
But this is always showing "The page could not be opened because the URL is invalid." Implementing onReceivedError() shows me ERROR_BAD_URL being fired.
I've tried replacing url with a hard-coded value "http://www.google.com" but I get the same error message. The page displays fine if I instead invoke the phone's browser with the URL.
The error only occurs on one of the phones I'm testing on (A Droid Eris running 2.1). There are no problems running on the emulator (I've tried 1.5 and 2.1) or on another phone.
Is there some configuration setting on the phone that could cause this? I don't know where to begin debugging this.
Upvotes: 2
Views: 1508
Reputation: 6030
Just found in docs that you have to give your app internet permission in your Manifest.xml.
<uses-permission android:name="android.permission.INTERNET" />
Upvotes: 1
Reputation: 51
Giving it ACCESS_NETWORK_STATUS/CHANGE_NETWORK_STATUS permissions solved the problem. (Possibly only one of those is actually required, I have not tested)
Upvotes: 3