Example usage for android.app Activity getSystemService

List of usage examples for android.app Activity getSystemService

Introduction

In this page you can find the example usage for android.app Activity getSystemService.

Prototype

@Override
    public Object getSystemService(@ServiceName @NonNull String name) 

Source Link

Usage

From source file:Main.java

public static void hideKeyboard(Activity activity) {
    imm = (InputMethodManager) activity.getSystemService(Context.INPUT_METHOD_SERVICE);
    imm.hideSoftInputFromWindow(activity.getCurrentFocus().getWindowToken(),
            InputMethodManager.HIDE_NOT_ALWAYS);
}

From source file:Main.java

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

From source file:Main.java

public static boolean isWifiEnable(Activity activitiy) {

    WifiManager wm = (WifiManager) activitiy.getSystemService(Context.WIFI_SERVICE);

    return wm.getWifiState() == WifiManager.WIFI_STATE_ENABLED;

}

From source file:Main.java

public static InputMethodManager getInputMethodManager(Activity activity) {
    return (InputMethodManager) activity.getSystemService(Context.INPUT_METHOD_SERVICE);
}

From source file:Main.java

public static String getDeviceId(Activity activity) {
    TelephonyManager tm = (TelephonyManager) activity
            .getSystemService(android.content.Context.TELEPHONY_SERVICE);
    return tm.getDeviceId();
}

From source file:Main.java

public static int getScreenHeight(Activity context) {
    WindowManager wm = (WindowManager) context.getSystemService(Context.WINDOW_SERVICE);
    int height = wm.getDefaultDisplay().getHeight();
    return height;

}

From source file:Main.java

public static ConnectivityManager getConnectivityManager(Activity activity) {
    return (ConnectivityManager) activity.getSystemService(Context.CONNECTIVITY_SERVICE);
}

From source file:Main.java

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

From source file:Main.java

public static void hideKeyboard(Activity activity) {
    InputMethodManager imm = (InputMethodManager) activity.getSystemService(Activity.INPUT_METHOD_SERVICE);
    imm.toggleSoftInput(InputMethodManager.HIDE_IMPLICIT_ONLY, 0);
}

From source file:Main.java

public static void vibrate(Activity activity, long time) {
    Vibrator vibrator = (Vibrator) activity.getSystemService(Context.VIBRATOR_SERVICE);
    vibrator.vibrate(time);//from  w  w  w  .ja  v a 2 s .  c  o m
}