1

i'm trying to make a browser app but the problem is that it doesn't connect to the internet

it's a multi tabbed so these are the codes:

main activity:

public class TabTestActivity extends TabActivity {
    /** Called when the activity is first created. */
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);
        TabHost host=getTabHost();
        host.addTab(host.newTabSpec("two")
                .setIndicator("facebook")
                .setContent(new Intent(this,facebrowser.class)));
        host.addTab(host.newTabSpec("one")
                .setIndicator("Google")
                .setContent(new Intent(this,googlebrowser.class)));

    }
}

tab1 activity:

public class facebrowser extends Activity {
    @Override
    public void onCreate(Bundle savedInstanceState){
        super.onCreate(savedInstanceState);
        WebView browse = new WebView(this);
        setContentView(browse);
        browse.loadUrl("http:\\www.facebook.com");
    }
}

tab2 activity:

public class googlebrowser extends Activity{
    @Override
    public void onCreate(Bundle savedInstanceState){
        super.onCreate(savedInstanceState);
        WebView browse = new WebView(this);
        setContentView(browse);
        browse.loadUrl("http:\\www.google.com");
    }
}

xml layout:

<?xml version="1.0" encoding="utf-8"?>
<TabHost
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@android:id/tabhost"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent" >
    <LinearLayout
        android:layout_width="fill_parent"
        android:layout_height="fill_parent"
        android:orientation="vertical" >
            <TabWidget
                android:id="@android:id/tabs"
                android:layout_width="fill_parent"
                android:layout_height="wrap_content" />
            <FrameLayout
                android:id="@android:id/tabcontent"
                android:layout_width="match_parent"
                android:layout_height="match_parent" />
    </LinearLayout>
</TabHost>

manifest :

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

    <uses-sdk android:minSdkVersion="8" />
    <uses-permission android:name="android.permission.ACCESS_WIFI_STATE"/>
    <uses-permission android:name="android.permission.INTERNET"/>
    <uses-permission android:name="android.permission.ACCESS_NETWORK_STATE"/>
    <application
        android:icon="@drawable/ic_launcher"
        android:label="@string/app_name" >
        <activity
            android:name=".TabTestActivity"
            android:label="@string/app_name" >
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />

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

        </activity>
        <activity android:name="facebrowser" android:label="name"></activity>
    </application>
</manifest>

and the pages tell me:

Web page not available

The Web page at http:/www.facebook.com might be temporarily down or it may have moved permanently to a new web address.

Here are some suggestions:

  • Check to make sure your device has a signal and data connection.
  • Reload this web page later.

View a cached copy of the web page from Google

Adam Lear
  • 38,111
  • 12
  • 81
  • 101
mohammed essam
  • 157
  • 1
  • 14

2 Answers2

1

instead of browse.loadUrl("http:\\www.facebook.com"); use browse.loadUrl("http://www.facebook.com");

that should work

For your Second Problem : You need to make a webviewclient

public class googlebrowser extends Activity{

    private class HelloWebViewClient extends WebViewClient {
        @Override
        public boolean shouldOverrideUrlLoading(WebView view, String url) {
            return false;
        }
    }


    @Override
    public void onCreate(Bundle savedInstanceState){
        super.onCreate(savedInstanceState);
        WebView browse = new WebView(this);
        setContentView(browse);

        browse.setWebViewClient(new HelloWebViewClient());

        browse.loadUrl("http://www.google.com");
    }
}
Sunny Kumar Aditya
  • 2,806
  • 4
  • 26
  • 38
0

Are you testing this all using an emulator? It's possible that that doesn't have internet connectivity. This is somewhat of a common problem. See the other Stackoverflow post here (http://stackoverflow.com/questions/2039964/how-to-connect-android-emulator-to-the-internet) that might help you troubleshoot.

loeschg
  • 29,961
  • 26
  • 97
  • 150