Java tutorial
//package com.java2s; import android.content.Context; import android.net.ConnectivityManager; import android.net.NetworkInfo; public class Main { public static int getNetWorkType(Context context) { ConnectivityManager cm = (ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE); NetworkInfo activeNetwork = cm.getActiveNetworkInfo(); if (activeNetwork == null) return -1; if (activeNetwork.getType() == ConnectivityManager.TYPE_WIFI) { return 1; } else if (activeNetwork.getType() == ConnectivityManager.TYPE_MOBILE) { return 0; } else { return 2; } } }