2011-10-03 120 views
1

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

例子將有助於 –

+0

關於評論:不,你並不需要使用'setUserAgentString()',它只是告訴服務器關於所使用的軟件和操作系統的客戶端上的一些信息的字符串。默認的一個很好。請參閱[用戶代理](http://en.wikipedia.org/wiki/User_agent) – 2011-10-04 15:00:23

回答

0

應用程序是否有權限訪問互聯網?

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

是的,它被添加到清單中'application'標籤的上方。 – DTSun

+0

有些人說,只有在「應用程序」標籤結束之前將其放在底部才能使用。那是你放的地方嗎? –

+0

否在「應用程序」標籤結束之前放置時,它不起作用。然後我把它放在'應用程序'標籤上面,一些頁面開始工作! – DTSun