因此,我创建了一个简单的应用程序,它将在“ webview”小部件上查看我的网页。它可以不间断地工作,并且在安装时很流畅,但事实是它不显示网页,而是显示“网页不可用”。
一切都很好,并且在Eclipse中没有错误,那就是代码:
private WebView myWebView;
@SuppressLint("SetJavaScriptEnabled")
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
myWebView = (WebView) findViewById(R.id.webView);
myWebView.loadUrl("http://www.aramco-values.webs.com");
Eclipse在OnCreate方法下初始化了SupportLint,我不知道这是否是问题所在,因为它必须存在,否则mtWebView无法正常工作。
表现:
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.aramcoapp"
android:versionCode="1"
android:versionName="1.0" >
<uses-sdk
android:minSdkVersion="11"
android:targetSdkVersion="12" />
<uses-permission android:name="android.permission.INTERNET" />
<application
android:allowBackup="true"
android:icon="@drawable/ic_launcher"
android:label="@string/app_name"
android:theme="@style/AppTheme" >
<activity
android:name="com.aramcoapp.MainActivity"
android:label="@string/app_name" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>
Eclipse警告我有关在创建应用程序开始时设置的SDK的信息
最小值= 11
目标= 12
最佳答案
为了访问Internet并在WebView中加载网页,必须将INTERNET
权限添加到Android Manifest文件中:
<uses-permission android:name="android.permission.INTERNET" />
资料来源:http://developer.android.com/reference/android/webkit/WebView.html
[编辑]
WebView webView = (WebView) findViewById(R.id.webview);
webView.loadUrl("http://www.aramco-values.webs.com");
webView.setWebViewClient(new WebViewClient() {
@Override
public void onReceivedError(WebView view, int errorCode, String description, String failingUrl) {
Log.i("WEB_VIEW_TEST", "error code:" + errorCode);
super.onReceivedError(view, errorCode, description, failingUrl);
}
});