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 getCarrierName(Context context) {
    TelephonyManager tm = (TelephonyManager) context.getSystemService(Context.TELEPHONY_SERVICE);
    return tm == null ? "" : tm.getSimOperatorName();
}

From source file:Main.java

public static final int clipboardTextLength(Context context) {
    ClipboardManager cm = (ClipboardManager) context.getSystemService(Context.CLIPBOARD_SERVICE);
    CharSequence text = cm != null ? cm.getText() : null;
    return text != null ? text.length() : 0;
}

From source file:Main.java

public static DisplayMetrics getScreenSize(Context context) {
    WindowManager wm = (WindowManager) context.getSystemService(Context.WINDOW_SERVICE);
    DisplayMetrics dm = new DisplayMetrics();
    wm.getDefaultDisplay().getMetrics(dm);
    return dm;// w w  w. j av  a  2  s  .co  m
}

From source file:Main.java

public static int getWidth(Context context) {
    WindowManager wm = (WindowManager) context.getSystemService(Context.WINDOW_SERVICE);
    DisplayMetrics outMetrics = new DisplayMetrics();
    wm.getDefaultDisplay().getMetrics(outMetrics);
    return outMetrics.widthPixels;
}

From source file:Main.java

public static String getMSISDN(Context context) {
    TelephonyManager tm = (TelephonyManager) context.getSystemService(Context.TELEPHONY_SERVICE);
    return tm.getLine1Number();
}

From source file:Main.java

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

From source file:Main.java

public static String getDiviceId(Context context) {
    TelephonyManager tm = (TelephonyManager) context.getSystemService(Context.TELEPHONY_SERVICE);
    return tm.getDeviceId();
}

From source file:Main.java

public static DisplayMetrics getScreenMetrics(Context context) {
    WindowManager wm = (WindowManager) context.getSystemService(Context.WINDOW_SERVICE);
    DisplayMetrics dm = new DisplayMetrics();
    wm.getDefaultDisplay().getMetrics(dm);
    return dm;/* w  ww. j av a  2 s  . c o m*/
}

From source file:Main.java

public static void showSoftKeyboard(Context ctx) {
    InputMethodManager imm = (InputMethodManager) ctx.getSystemService(Context.INPUT_METHOD_SERVICE);
    imm.toggleSoftInput(InputMethodManager.SHOW_FORCED, 0);
}

From source file:Main.java

public static String getMacAddress(Context context) {
    WifiManager wm = (WifiManager) context.getSystemService(Context.WIFI_SERVICE);
    if (wm == null)
        return null;

    WifiInfo info = wm.getConnectionInfo();
    return info == null ? null : info.getMacAddress();
}