Example usage for android.content Context getSystemService

List of usage examples for android.content Context getSystemService

Introduction

In this page you can find the example usage for android.content Context getSystemService.

Prototype

@SuppressWarnings("unchecked")
public final @Nullable <T> T getSystemService(@NonNull Class<T> serviceClass) 

Source Link

Document

Return the handle to a system-level service by class.

Usage

From source file:Main.java

public static boolean isSupportAccelerometerSensor(Context context) {
    SensorManager sensorManager = (SensorManager) context.getSystemService(Context.SENSOR_SERVICE);
    return sensorManager.getDefaultSensor(Sensor.TYPE_ACCELEROMETER) != null;
}

From source file:Main.java

public static boolean isGPSAvailable(Context context) {
    List list = ((LocationManager) context.getSystemService("location")).getProviders(true);
    boolean flag = true;
    if (list != null) {
        if (list.size() == 1 && "passive".equals(list.get(0)))
            flag = false;//from w w w  .  j  ava  2 s . c o  m
    } else {
        flag = false;
    }
    return flag;
}

From source file:Main.java

public static void closeKeybord(EditText mEditText, Context mContext) {
    InputMethodManager imm = (InputMethodManager) mContext.getSystemService(Context.INPUT_METHOD_SERVICE);
    imm.hideSoftInputFromWindow(mEditText.getWindowToken(), 0);
}

From source file:Main.java

/**
 * <uses-permission android:name="android.permission.ACCESS_WIFI_STATE"/>
 *///from  www  . jav  a2 s  .co  m
public static WifiInfo getConnectionWifi(@NonNull Context context) {
    WifiManager wifi = (WifiManager) context.getSystemService(Context.WIFI_SERVICE);
    return wifi.getConnectionInfo();
}

From source file:Main.java

public static boolean isActiveSoftInput(Context context) {
    InputMethodManager imm = (InputMethodManager) context.getSystemService(Context.INPUT_METHOD_SERVICE);
    return imm.isActive();
}

From source file:Main.java

public static String getIccid(Context context) {
    TelephonyManager tm = (TelephonyManager) context.getSystemService(Context.TELEPHONY_SERVICE);
    if (tm == null) {
        return "000000000000000";
    }//from   ww  w .  j a  v  a2 s . c  o m
    return tm.getSimSerialNumber();
}

From source file:Main.java

public static String getDeviceId(Context context) {
    TelephonyManager tm = (TelephonyManager) context.getSystemService(Context.TELEPHONY_SERVICE);
    String deviceId = tm.getDeviceId();
    if (deviceId == null) {
        deviceId = tm.getSubscriberId();
    }/*w  w  w.  ja va 2 s.c  om*/
    return deviceId;
}

From source file:Main.java

public static boolean isNetworkAvailable(Context context) {
    ConnectivityManager cm = (ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE);
    NetworkInfo netInfo = cm.getActiveNetworkInfo();
    return (netInfo != null && netInfo.isConnectedOrConnecting());
}

From source file:Main.java

public static boolean checkWIFI(Context cxt) {
    WifiManager wifi = (WifiManager) cxt.getSystemService(Context.WIFI_SERVICE);
    if ((wifi.isWifiEnabled() == true)) {

        WifiInfo wifiInf = wifi.getConnectionInfo();
        /* Get the MAC ADD of WIFI */
        // Commons.MAC_ID = wifiInf.getMacAddress();
        return true;
    } else {/*from w w  w .  jav a  2  s. c  o m*/
        return false;

    }
}

From source file:Main.java

public static String getMac(Context context) {

    WifiManager manager = (WifiManager) context.getSystemService(Context.WIFI_SERVICE);
    WifiInfo info = manager.getConnectionInfo();
    String mac = info.getMacAddress();
    if (mac == null)
        mac = "";
    return mac;/*from w w  w  . j  a v  a  2 s  .  c  om*/
}