Slide show

Total Pageviews

Powered by Blogger.

Translate

Search This Blog

Pages

CHECK INTERNET THROUGH SPLASH IN ANDROID


NETWORK CHECK CLASS IN ANDROID:-

import android.content.Context;
import android.net.ConnectivityManager;
import android.net.NetworkInfo;

public class ApplicationUtility {
    ConnectivityManager connectivityManager;
    NetworkInfo info;
   
    public boolean checkConnection(Context context) {
        boolean flag = false;
        try {
            connectivityManager = (ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE);
            info = connectivityManager.getActiveNetworkInfo();

            if (info.getType() == ConnectivityManager.TYPE_WIFI) {
                System.out.println(info.getTypeName());
                flag = true;
            }
            if (info.getType() == ConnectivityManager.TYPE_MOBILE) {
                System.out.println(info.getTypeName());
                flag = true;
            }
        } catch (Exception exception) {
            System.out.println("Exception at network connection....."
                    + exception);
        }
        return flag;
    }
   
}

SPLASH SCREEN CODE IN ANDROID:-


import java.util.Timer;
import java.util.TimerTask;

import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.widget.Toast;

public class Splash extends Activity {

    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.splash);

        Timer t = new Timer();
        boolean checkConnection=new ApplicationUtility().checkConnection(this);
        if (checkConnection) {
            t.schedule(new splash(), 3000);
        } else {
            Toast.makeText(Splash.this,
                    "connection not found...plz check connection", 3000).show();
        }
    }

    class splash extends TimerTask {

        @Override
        public void run() {
            Intent i = new Intent(Splash.this,LoginActivity.class);
            finish();
            startActivity(i);
        }

    }

   

}

XML CODE OF SPLASH SCREEN:-


<?xml version="1.0" encoding="utf-8" ?>
  <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:orientation="vertical" android:layout_width="fill_parent" android:layout_height="fill_parent" android:background="@drawable/guggo" />
 
 
           RUN  & ENJOY THE SPLASH WITH CHECK INTERNET 


         THANKS.

No comments:

vehicles

business

health