我的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