2011-10-03 114 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