2011-11-09 21 views
3

私は両方の間にヘッダー、フッター、WebViewを持つAndroidアプリケーション(Android 2.3.3)を作成しています。問題は、WebViewがWebページを開いていないことです。 (注:私はエミュレータ上でアプリケーションを実行しています)。WebViewはWebページを開いていませんが、ブラウザは(エラー:Webページが利用できません)

Androidブラウザを使用してウェブページを開こうとしましたが、ウェブページが正しく開かれました。私はまた試みた:

Intent intent = new Intent(Intent.ACTION_VIEW, Uri.parse(url)); 
startActivity(intent); 

そしてコードは正しく動作する(ブラウザのページを開く)。

私はwww.google.comで働いていて、自分自身のドメインで、私は両方のウェブページのIPアドレスを使って作業しています(Googleの場合は72.14.204.147、自分の場合はip私自身のdevサーバの)。

また、最も一般的な回答が書かれる前に、私はすでにアプリケーションタグの前に<uses-permission android:name="android.permission.INTERNET" />を持っています。

誰もがそれを要求する前に、私は、コードを追加している:

活動のJavaファイル:

public class MyActivity extends Activity { 

//Global Variables 
WebView mainWebView; 

/** Called when the activity is first created. */ 
@Override 
public void onCreate(Bundle savedInstanceState) { 
    super.onCreate(savedInstanceState); 
    setContentView(R.layout.main); 

    loadActivityViews(); 

    mainWebView.getSettings().setJavaScriptEnabled(true); 
    mainWebView.loadUrl("www.google.com"); 
    mainWebView.setWebViewClient(new MyWebViewClient()); 
} 

/** Loads all global views of the Activity */ 
private void loadActivityViews(){ 
    mainWebView = (WebView) findViewById(R.id.index_main_web_view); 
} 

//Internal Classes 

/* 
* MyWebView Class 
* 
* Forces links to open in the same webView 
* Handles the back button. 
* */ 

public class MyWebViewClient extends WebViewClient { 

    @Override 
    public boolean shouldOverrideUrlLoading(WebView view, String url) { 
     view.loadUrl(url); 
     return true; 
    } 

    @Override 
    public boolean shouldOverrideKeyEvent(WebView view, KeyEvent event) { 
     if ((event.getKeyCode() == KeyEvent.KEYCODE_BACK) && view.canGoBack()) { 
      view.goBack(); 
      return true; 
     } 

     return super.shouldOverrideKeyEvent(view, event); 
    } 
} 
} 

アンドロイドマニフェスト: (注:それは持っている "android.permission.INTERNETあなた" の前にアプリケーションタグ)

<?xml version="1.0" encoding="utf-8"?> 
<manifest xmlns:android="http://schemas.android.com/apk/res/android" 
    package="pixable.android" 
    android:versionCode="1" 
    android:versionName="1.0" > 
    <uses-permission android:name="android.permission.INTERNET" /> 

    <uses-sdk android:minSdkVersion="10" /> 
    <uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" /> 


    <application 
     android:icon="@drawable/ic_launcher" 
     android:label="@string/app_name" > 

     <activity 
      android:label="@string/app_name" 
      android:name=".MyActivity" 
      android:theme="@android:style/Theme.Black.NoTitleBar.Fullscreen" > 
      <intent-filter > 
       <action android:name="android.intent.action.MAIN" /> 

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

</manifest> 

main.xml(Iドン; tはその重要なのだと思うが、私は念のためにそれを追加している)

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    android:layout_width="fill_parent" 
    android:layout_height="fill_parent" 
    android:orientation="vertical" > 

    <RelativeLayout 
     android:id="@+id/index_main_layout" 
     android:layout_width="fill_parent" 
     android:layout_height="wrap_content" 
     android:background="#FFFFFF" > 

     <RelativeLayout 
      android:id="@+id/index_header" 
      android:layout_width="fill_parent" 
      android:layout_height="wrap_content" 
      android:layout_alignParentLeft="true" 
      android:layout_alignParentTop="true" 
      android:background="#000000" > 

      ... My header butons ... 

     </RelativeLayout> 

     <WebView 
      android:id="@+id/index_main_web_view" 
      android:layout_width="match_parent" 
      android:layout_height="wrap_content" 
      android:layout_alignParentLeft="true" 
      android:layout_below="@+id/index_header" 
      android:layout_above="@+id/index_botom_layout" /> 

     <LinearLayout 
      android:id="@+id/index_botom_layout" 
      android:layout_width="fill_parent" 
      android:layout_height="50px" 
      android:layout_alignParentBottom="true" 
      android:background="#000000" 
      android:orientation="horizontal" > 

      ... My Footer Butons ... 

     </LinearLayout> 

    </RelativeLayout> 

</LinearLayout> 

答えて

5

あなたの問題は、URLの前にhttp://が付いていないと思います。私はhttp://www.google.comの作品を賭ける。

+0

問題を解決しました。ありがとうございます。私はもっ​​と複雑な何かを期待していた。 –

+0

np、幸せな助け。 –

関連する問題