Sriram
Sriram

Reputation: 10558

WebView page not available - Android

I have a basic WebView application that should display www.google.com. Though the website can be accessed through the in-built browser, I am not able to do so from the WebView. I have gone through a large number of questions on various forums and incorporated all suggestions, but nothing seems to have worked. I have ensured:
1. The uses-permission tag for allowing internet access is a child of the manifest tag.
2. Enabled javascript for the WebView.
The manifest file:

<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>  

Layout:

<?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;
    }
}

Upvotes: 1

Views: 10734

Answers (4)

Manish Nath
Manish Nath

Reputation: 21

You need to add http:// in the url string...the url must look like this

String url = "http://www.google.com/";

now do

webview.loadurl(url);

Upvotes: 0

Shadow
Shadow

Reputation: 6899

WebView wt;

wt.loadUrl("http://www.google.com/");

and sometimes in android 4.0 it will be blank, use android:hardwareAccelerated="true" in manifest file.

Upvotes: 3

Janmejoy
Janmejoy

Reputation: 2721

String url = "https://www.google.co.in/";

or else

super.loadUrl("https://www.google.co.in//");

Upvotes: 6

Stefan de Bruijn
Stefan de Bruijn

Reputation: 6319

Try adding http:// in front of your link

Upvotes: 4

Related Questions