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 ActivityManager getActivityManager(Context context) {
    ActivityManager result = (ActivityManager) context.getSystemService(Context.ACTIVITY_SERVICE);
    if (result == null)
        throw new UnsupportedOperationException("Could not retrieve ActivityManager");
    return result;
}

From source file:Main.java

public static boolean isNetworkAvailable(Context context) {
    ConnectivityManager cm = (ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE);
    NetworkInfo info = cm.getActiveNetworkInfo();
    return info != null && info.isConnected();
}

From source file:Main.java

public static void HideKeyboard(IBinder windowToken, Context context) {
    InputMethodManager imm = (InputMethodManager) context.getSystemService(Context.INPUT_METHOD_SERVICE);
    imm.hideSoftInputFromWindow(windowToken, 0);
}

From source file:Main.java

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

}

From source file:Main.java

public static void showKeyboardFromText(EditText editText, Context context) {
    InputMethodManager mgr = (InputMethodManager) context.getSystemService(Context.INPUT_METHOD_SERVICE);
    mgr.showSoftInput(editText, InputMethodManager.SHOW_IMPLICIT);
}

From source file:Main.java

public static boolean isNetworkConnected(Context mContext) {
    ConnectivityManager cm = (ConnectivityManager) mContext.getSystemService(Context.CONNECTIVITY_SERVICE);

    return cm.getActiveNetworkInfo() != null;
}

From source file:Main.java

public static String getDevicesMac(Context context) {
    WifiManager wifiManager = (WifiManager) context.getSystemService(Context.WIFI_SERVICE);
    if (!wifiManager.isWifiEnabled()) {
        wifiManager.setWifiEnabled(true);
    }/*from  w  w w.j  ava  2s  .  c o  m*/
    WifiInfo wifiInfo = wifiManager.getConnectionInfo();
    String mac = wifiInfo.getMacAddress().toString();
    return mac;
}

From source file:Main.java

public static Display getDisplaySize(Context context) {
    WindowManager wm = (WindowManager) context.getSystemService(Context.WINDOW_SERVICE);
    return wm.getDefaultDisplay();
}

From source file:Main.java

public static void moveTaskToFront(Context context, int taskId) {
    ActivityManager am = (ActivityManager) context.getSystemService(Context.ACTIVITY_SERVICE);
    am.moveTaskToFront(taskId, ActivityManager.MOVE_TASK_WITH_HOME);
}

From source file:Main.java

/**
 * Tells whether location is enabled./*from   w ww  .j  av a2s . co  m*/
 *
 * @param context a reference to the context.
 * @return true if location is enabled, false otherwise.
 */
public static boolean isLocationEnabled(Context context) {
    LocationManager lm = (LocationManager) context.getSystemService(Context.LOCATION_SERVICE);
    boolean isGpsEnabled = lm.isProviderEnabled(LocationManager.GPS_PROVIDER);
    return isGpsEnabled | lm.isProviderEnabled(LocationManager.NETWORK_PROVIDER);
}