2012-03-30 67 views
-1

我已經把清單從WebView中無法上網的Android 2.1,而正常的瀏覽器不工作

​​

,但我認爲它不會對Android 2.1的我應該怎麼把工作呢?

源代碼只是來自Google http://developer.android.com/resources/tutorials/views/hello-webview.html的官方教程。

import android.app.Activity; 
import android.os.Bundle; 
import android.webkit.WebView; 

public class WebViewActivity extends Activity { 

    WebView webview; 

    /** Called when the activity is first created. */ 
    @Override 
    public void onCreate(Bundle savedInstanceState) { 
     super.onCreate(savedInstanceState); 
     setContentView(R.layout.main); 
     webview = (WebView) findViewById(R.id.webview); 
     webview.getSettings().setJavaScriptEnabled(true); 
     webview.loadUrl("http://google.com");   
    } 
} 
+0

添加您的代碼在這裏.. – Bhavin 2012-03-30 11:24:51

+0

可以爲您發佈您的代碼? – 2012-03-30 11:33:00

+0

對不起,我忘了它只是官方嘖嘖現在我更新 – user310291 2012-03-30 12:08:30

回答

1

該權限適用於Android 2.1。您發佈的代碼將適用於Android 2.1。

我只是測試它在模擬器中,如果我不提供許可,我會在WebView中收到一個錯誤:

Web Page Not Available 
The web page at http://www.google.com/ might be temporarily down [...] 

添加權限解決了。

確保將您的許可添加到適當的位置。它必須直接位於<清單>元素內。如果將其放置在<應用程序>元素內,則它不起作用。

這工作:

<?xml version="1.0" encoding="utf-8"?> 
<manifest xmlns:android="http://schemas.android.com/apk/res/android" 
    package="com.test.testwebview" 
    android:versionCode="1" 
    android:versionName="1.0" > 

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

    <uses-sdk android:minSdkVersion="7" /> 

    <application 
     android:icon="@drawable/ic_launcher" 
     android:label="@string/app_name" > 
     <activity 
      android:label="@string/app_name" 
      android:name=".TestWebViewActivity" > 
      <intent-filter > 
       <action android:name="android.intent.action.MAIN" /> 

       <category android:name="android.intent.category.LAUNCHER" /> 
      </intent-filter> 
     </activity> 
    </application> 
</manifest> 
+0

愚蠢的我非常感謝:) – user310291 2012-03-31 02:49:36

相關問題