Main.java Source code

Java tutorial

Introduction

Here is the source code for Main.java

Source

//package com.java2s;
//License from project: Apache License 

import android.content.Context;

import android.net.ConnectivityManager;
import android.net.NetworkInfo;

public class Main {
    /**
     * get mobile NetWork Type
     * 
     * @param context
     * @return
     */
    public static String getNetWorkType(Context context) {
        ConnectivityManager connectivityManager = (ConnectivityManager) context
                .getSystemService(Context.CONNECTIVITY_SERVICE);
        NetworkInfo workinfo = connectivityManager.getActiveNetworkInfo();
        if (workinfo != null) {
            if (workinfo.getType() == ConnectivityManager.TYPE_BLUETOOTH) {
                return "b";
            }
            if (workinfo.getType() == ConnectivityManager.TYPE_MOBILE) {
                return "m";
            }
            if (workinfo.getType() == ConnectivityManager.TYPE_WIFI) {
                return "w";
            }
        }
        return null;
    }
}