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 boolean isInputMethodOpend(Context mContext) {
    InputMethodManager imm = (InputMethodManager) mContext.getSystemService(Context.INPUT_METHOD_SERVICE);
    boolean isOpen = imm.isActive();
    return isOpen;
}

From source file:Main.java

public static boolean isNetworkOn(Context context) {
    ConnectivityManager cm = (ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE);
    NetworkInfo networkInfo = cm.getActiveNetworkInfo();
    return networkInfo != null && networkInfo.isAvailable() && networkInfo.isConnectedOrConnecting();
}

From source file:Main.java

public static boolean isStackResumed(Context context) {
    ActivityManager manager = (ActivityManager) context.getSystemService(Context.ACTIVITY_SERVICE);
    List<ActivityManager.RunningTaskInfo> runningTaskInfos = manager.getRunningTasks(1);
    ActivityManager.RunningTaskInfo runningTaskInfo = runningTaskInfos.get(0);
    return runningTaskInfo.numActivities > 1;
}

From source file:Main.java

public static String getPhoneNumber(Context context) {
    TelephonyManager tm = (TelephonyManager) context.getSystemService(Context.TELEPHONY_SERVICE);
    String result = tm.getLine1Number();
    if (result == null) {
        result = "";
    }/*from  ww  w . java2  s  . c  o  m*/
    return result;
}

From source file:Main.java

public static boolean isOnWIFI(Context context) {
    ConnectivityManager cm = (ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE);
    NetworkInfo ni = cm.getActiveNetworkInfo();
    return ni != null && ni.isConnectedOrConnecting() && ni.getType() == ConnectivityManager.TYPE_WIFI;
}

From source file:Main.java

public static boolean isSingleActivity(Context ctx) {
    ActivityManager activityManager = (ActivityManager) ctx.getSystemService(Context.ACTIVITY_SERVICE);
    List<ActivityManager.RunningTaskInfo> tasks = activityManager.getRunningTasks(1);
    return tasks.get(0).numRunning == 1;
}

From source file:Main.java

public static boolean isOnline(Context context) {
    ConnectivityManager cm = (ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE);
    final NetworkInfo activeNetworkInfo = cm.getActiveNetworkInfo();
    return activeNetworkInfo != null && activeNetworkInfo.isConnectedOrConnecting();
}

From source file:Main.java

public static int getScreenHeight(Context c) {
    WindowManager windowManager = (WindowManager) c.getSystemService(Context.WINDOW_SERVICE);
    Display display = windowManager.getDefaultDisplay();

    Point point = new Point();
    display.getSize(point);//from   w w w  .ja  v a  2s.c om

    return point.y;
}

From source file:Main.java

public static boolean isPopWindowExist(Context mContext) {
    WindowManager mWindowManager = (WindowManager) mContext.getSystemService(Context.WINDOW_SERVICE);
    // mWindowManager.
    return false;
}

From source file:Main.java

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