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 String getWifiMac1(Context context) {
    WifiManager wifi = (WifiManager) context.getSystemService(Context.WIFI_SERVICE);
    if (wifi != null) {
        WifiInfo info = wifi.getConnectionInfo();
        String mac = info.getMacAddress();
        return mac;
    }//from  w  w  w  .  ja  v a  2s  . co m

    return "";
}

From source file:Main.java

public static int getScreenWidth(Context context) {
    WindowManager windowManager = (WindowManager) context.getSystemService(Context.WINDOW_SERVICE);
    return windowManager.getDefaultDisplay().getWidth();
}

From source file:Main.java

public static String getIMEI(Context context) {
    TelephonyManager tm = (TelephonyManager) context.getSystemService(Context.TELEPHONY_SERVICE);

    String imei = tm.getSimSerialNumber();
    return imei;//from w ww .java  2 s . c o  m
}

From source file:Main.java

public static int getScreenWidth(Context context) {
    WindowManager manager = (WindowManager) context.getSystemService(Context.WINDOW_SERVICE);
    DisplayMetrics dm = new DisplayMetrics();
    manager.getDefaultDisplay().getMetrics(dm);
    return dm.widthPixels;
}

From source file:Main.java

public static boolean canMakeCall(Context ctx) {
    TelephonyManager manager = (TelephonyManager) ctx.getSystemService(Context.TELEPHONY_SERVICE);
    return manager.getSimState() == TelephonyManager.SIM_STATE_READY
            && (manager.getPhoneType() == TelephonyManager.PHONE_TYPE_GSM
                    || manager.getPhoneType() == TelephonyManager.PHONE_TYPE_CDMA);
}

From source file:Main.java

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

From source file:Main.java

/**
 * @param context//from w  w  w  . j  a v a2  s .c  o  m
 * @return DisplayMetrics.
 */
public static DisplayMetrics getDisplayMetrics(Context context) {
    WindowManager wm = (WindowManager) context.getSystemService(Context.WINDOW_SERVICE);
    DisplayMetrics metrics = new DisplayMetrics();
    wm.getDefaultDisplay().getMetrics(metrics);
    return metrics;
}

From source file:Main.java

public static void showSoftInput(Context context) {
    InputMethodManager imm = (InputMethodManager) context.getSystemService(Context.INPUT_METHOD_SERVICE);
    imm.toggleSoftInput(InputMethodManager.RESULT_UNCHANGED_SHOWN, InputMethodManager.HIDE_NOT_ALWAYS);
}

From source file:Main.java

public static int getScreenWidth(Context context) {
    WindowManager manager = (WindowManager) context.getSystemService(Context.WINDOW_SERVICE);
    manager.getDefaultDisplay().getMetrics(metric);
    return metric.widthPixels;
}

From source file:Main.java

public static int getRunningProcessNumber(Context context) {
    ActivityManager am = (ActivityManager) context.getSystemService(context.ACTIVITY_SERVICE);
    List<RunningAppProcessInfo> runningAppProcesses = am.getRunningAppProcesses();
    return runningAppProcesses.size();
}