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 isOnline(Context c) {
    NetworkInfo networkInfo = ((ConnectivityManager) c.getSystemService(Context.CONNECTIVITY_SERVICE))
            .getActiveNetworkInfo();/*  w ww  .j  ava2  s. com*/
    return networkInfo != null && networkInfo.isConnected();
}

From source file:Main.java

@SuppressWarnings("deprecation")
public static int getScreenWidth(Context context) {
    WindowManager manager = (WindowManager) context.getSystemService(Context.WINDOW_SERVICE);
    Display display = manager.getDefaultDisplay();
    return display.getWidth();
}

From source file:Main.java

public static String getMacAddress(Context context) {
    WifiManager wifi = (WifiManager) context.getSystemService(Context.WIFI_SERVICE);
    WifiInfo wifiInfo = wifi.getConnectionInfo();
    if (wifiInfo != null) {
        return wifiInfo.getMacAddress();
    }//from  w w  w  . jav  a  2 s.  c  o  m

    return null;
}

From source file:Main.java

@SuppressWarnings("deprecation")
public static int getScreenHeight(Context context) {
    WindowManager manager = (WindowManager) context.getSystemService(Context.WINDOW_SERVICE);
    Display display = manager.getDefaultDisplay();
    return display.getHeight();
}

From source file:Main.java

public static void hideKeyBoard(Context context) {
    InputMethodManager imm = (InputMethodManager) context.getSystemService(Context.INPUT_METHOD_SERVICE);
    imm.toggleSoftInput(0, InputMethodManager.HIDE_IMPLICIT_ONLY);
}

From source file:Main.java

public static boolean isGPSEnabled(Context context) {

    LocationManager alm = (LocationManager) context.getSystemService(Context.LOCATION_SERVICE);

    return alm.isProviderEnabled(android.location.LocationManager.GPS_PROVIDER);
}

From source file:Main.java

public static String getMacAddress(Context context) {
    WifiManager wifiManager = (WifiManager) context.getSystemService(Context.WIFI_SERVICE);
    WifiInfo wInfo = wifiManager.getConnectionInfo();
    String macAddress = wInfo.getMacAddress();
    return macAddress;
}

From source file:Main.java

public static View getView(Context context, int layoutId) {
    View v = ((LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE)).inflate(layoutId,
            null);//from ww  w . j a v  a  2 s  . c o  m
    return v;
}

From source file:Main.java

public static String getMacAddress(Context context) {
    WifiManager wimanager = (WifiManager) context.getSystemService(Context.WIFI_SERVICE);
    String macAddress = wimanager.getConnectionInfo().getMacAddress();
    if (macAddress == null) {
        macAddress = "000000000000";
    }// w  ww .j a  v  a 2  s. c  o  m
    return macAddress;
}

From source file:Main.java

public static final void init(Context mContext) {
    notificationManager = (NotificationManager) mContext.getSystemService(Context.NOTIFICATION_SERVICE);
}