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 int getRamFree(Activity mActivity) {
    ActivityManager.MemoryInfo mi = new ActivityManager.MemoryInfo();
    ActivityManager activityManager = (ActivityManager) mActivity.getSystemService(Activity.ACTIVITY_SERVICE);
    activityManager.getMemoryInfo(mi);/* w w  w.  j a v  a2s .  c  o  m*/

    int free = (int) (mi.availMem / 1048576L);
    return free;
}

From source file:Main.java

public static int getRamTotalMB(Activity mActivity) {
    ActivityManager.MemoryInfo mi = new ActivityManager.MemoryInfo();
    ActivityManager activityManager = (ActivityManager) mActivity.getSystemService(Activity.ACTIVITY_SERVICE);
    activityManager.getMemoryInfo(mi);/*w ww  . j  ava2s .com*/

    int total = (int) (mi.totalMem / 1048576L);
    return total;
}

From source file:Main.java

public static int getRamUsing(Activity mActivity) {
    ActivityManager.MemoryInfo mi = new ActivityManager.MemoryInfo();
    ActivityManager activityManager = (ActivityManager) mActivity.getSystemService(Activity.ACTIVITY_SERVICE);
    activityManager.getMemoryInfo(mi);/*w w w .  j  a  va  2s  . c om*/

    float availableMegs = (mi.totalMem - mi.availMem) / 1048576L;
    return (int) availableMegs;
}

From source file:Main.java

/**
 * Helper Method to hide the keyboard//w  ww  . ja  v  a 2  s.  c om
 */
public static void hideKeyboard(Activity activity) {
    View view = activity.getCurrentFocus();
    if (view != null) {
        ((InputMethodManager) activity.getSystemService(Context.INPUT_METHOD_SERVICE))
                .hideSoftInputFromWindow(view.getWindowToken(), InputMethodManager.HIDE_NOT_ALWAYS);
    }
}

From source file:Main.java

public static void hideSoftKeyBoard(Activity activity) {
    if (null == activity.getCurrentFocus()) {
        return;/*from   w ww. j av  a  2 s  .  c  o m*/
    }
    InputMethodManager imm = (InputMethodManager) activity.getSystemService(Context.INPUT_METHOD_SERVICE);
    imm.hideSoftInputFromWindow(activity.getCurrentFocus().getWindowToken(),
            InputMethodManager.HIDE_NOT_ALWAYS);
}

From source file:Main.java

public static void hideSoftKeyboard(Activity activity) {
    View view = activity.getCurrentFocus();
    if (view != null) {
        InputMethodManager imm = (InputMethodManager) activity.getSystemService(Context.INPUT_METHOD_SERVICE);
        imm.hideSoftInputFromWindow(view.getWindowToken(), 0);
    }/*from w  ww  .j  a va2 s  . co  m*/
}

From source file:Main.java

public static void hideKeyboard(Activity activity) {
    if (activity != null && activity.getCurrentFocus() != null) {
        InputMethodManager inputManager = (InputMethodManager) activity
                .getSystemService(Context.INPUT_METHOD_SERVICE);
        inputManager.hideSoftInputFromWindow(activity.getCurrentFocus().getWindowToken(),
                InputMethodManager.HIDE_NOT_ALWAYS);
    }/*from w w w  .j a v  a2  s .  c o m*/
}

From source file:Main.java

public static void hideSoftKeyboard(Activity activity) {
    if (activity.getCurrentFocus() != null) {
        InputMethodManager inputMethodManager = (InputMethodManager) activity
                .getSystemService(Context.INPUT_METHOD_SERVICE);
        inputMethodManager.hideSoftInputFromWindow(activity.getCurrentFocus().getWindowToken(), 0);
    }//ww w.ja  v  a 2  s  .co m
}

From source file:Main.java

public static void hide(final Activity activity) {
    View view = activity.getCurrentFocus();
    if (view != null) {
        InputMethodManager imm = (InputMethodManager) activity.getSystemService(Context.INPUT_METHOD_SERVICE);
        imm.hideSoftInputFromWindow(view.getWindowToken(), 0);
    }/*from  w w w.j  a v  a 2s .c  o  m*/
}

From source file:Main.java

public static void hideSoftKeyboard(Activity activity) {
    if (activity != null && activity.getCurrentFocus() != null) {
        InputMethodManager inputMethodManager = (InputMethodManager) activity
                .getSystemService(Activity.INPUT_METHOD_SERVICE);
        inputMethodManager.hideSoftInputFromWindow(activity.getCurrentFocus().getWindowToken(), 0);
    }/*w  w  w  .j a  v  a2s .c  o m*/
}