我的android应用程序无法打开某些网页。相同的网址在普通的网页浏览器中工作正常。感谢您的建议。Android应用程序无法打开某些网页?
Error Msg: **Web Page not available**
The web page at www.talladega.edu might be temporarily down or
它可能已永久移动到新的Web地址。
**Here are some suggestions:**
- Check signal and data connection
- Reload this page later
- View a cached copy of the web page from Google
请让我知道我做错了什么。谢谢你的时间 !
/** Called when the activity is first created. */
**@SuppressWarnings("static-access")**
@Override
public void onCreate(Bundle bundle) {
super.onCreate(bundle);
Bundle extras = getIntent().getExtras();
if (extras == null) {
return;
}
pageLink = extras.getString("pageLink");
if (pageLink != null) {
setContentView(R.layout.displayview);
WebView web = (WebView) findViewById(R.id.webview);
web.enablePlatformNotifications();
web.getSettings().setJavaScriptEnabled(true);
web.loadUrl(pageLink);
web.setWebViewClient(new localWebViewClient());
//web.getSettings().setUserAgentString("silly_to_do_this"); --- **do I need to set this ?**
}
}
private class localWebViewClient extends WebViewClient {
@Override
public boolean shouldOverrideUrlLoading(WebView view, String url) {
view.loadUrl(url);
return true;
}
}
=== displayview.xml ===
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical" android:layout_width="match_parent"
android:layout_height="match_parent" android:background="@color/pageBackGroundColor">
<WebView android:id="@+id/webview"
android:layout_width="fill_parent"
android:layout_height="fill_parent" android:background="@color/pageBackGroundColor"
/>
</LinearLayout>
例子将有助于 –
关于评论:不,你并不需要使用'setUserAgentString()',它只是告诉服务器关于所使用的软件和操作系统的客户端上的一些信息的字符串。默认的一个很好。请参阅[用户代理](http://en.wikipedia.org/wiki/User_agent) – 2011-10-04 15:00:23