WebView page n'est pas disponible - Android
J'ai une base WebView
application qui doit s'afficher www.google.com. Si le site peut être consulté par le biais de l'intégré dans le navigateur, je ne suis pas en mesure de le faire à partir de la WebView
. Je suis passé par un grand nombre de questions sur différents forums, et d'intégrer toutes les suggestions, mais rien ne semble avoir fonctionné. J'ai veillé à:
1. Le uses-permission
balise pour permettre l'accès à internet est un enfant de la manifest
tag.
2. Activé javascript pour la WebView.
Le fichier manifeste:
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.sriram.hellowebview"
android:versionCode="1"
android:versionName="1.0" >
<uses-permission android:name="android.permission.INTERNET"></uses-permission>
<uses-sdk
android:minSdkVersion="7"
android:targetSdkVersion="15" />
<application
android:icon="@drawable/ic_launcher"
android:label="@string/app_name"
android:theme="@style/AppTheme" >
<activity
android:name=".helloWebview"
android:label="@string/title_activity_hello_webview" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>
</manifest>
Mise en page:
<?xml version="1.0" encoding="utf-8" ?>
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical">
<WebView
android:id="@+id/helloWebview"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
/>
</LinearLayout>
Code:
/* Program to create sample webview.
* Steps:
* 1. Create webview.
* 2. Show some website in it.
* 3. Show some transitions as well.
*/
package com.sriram.hellowebview;
import android.app.Activity;
import android.os.Bundle;
import android.util.Log;
import android.view.Menu;
import android.webkit.WebView;
public class helloWebview extends Activity {
WebView myWebview;
String url = "www.google.com";
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_hello_webview);
Log.v(this.toString(), "Starting activity.");
myWebview = (WebView) findViewById(R.id.helloWebview);
Log.v(this.toString(), "Getting settings.");
myWebview.getSettings().setJavaScriptEnabled(true);
Log.v(this.toString(), "Loading URL now.");
myWebview.loadUrl(url);
Log.v(this.toString(), "Loaded URL.");
//open all links within the same webview.
//myWebview.setWebViewClient(new WebViewClient());
//Log.v(this.toString(), "All done here.");
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
getMenuInflater().inflate(R.menu.activity_hello_webview, menu);
return true;
}
}
Vous devez vous connecter pour publier un commentaire.
ou d'autre
Essayez d'ajouter http://devant votre lien
et parfois dans android 4.0, il sera vide, utilisez le
android:hardwareAccelerated="true"
dans le fichier manifest.Vous devez ajouter l'adresse http://dans l'url de la chaîne de...l'url doit ressembler à ceci
String url = "http://www.google.com/";
maintenant faire
webview.loadurl(url);