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 isScreenOn(Context ctx) {
    PowerManager pm = (PowerManager) ctx.getSystemService(Context.POWER_SERVICE);
    return pm.isScreenOn();
}

From source file:Main.java

public static boolean isMobileNetworkOpen(Context context) {
    return ((ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE)).getNetworkInfo(0)
            .isConnected();//from   w ww . j  a  v a 2 s  .  com
}

From source file:Main.java

public static ActivityManager getManager(Context context) {
    return (ActivityManager) context.getSystemService(Context.ACTIVITY_SERVICE);
}

From source file:Main.java

public static void vibrate(Context context) {
    Vibrator vibrator = (Vibrator) context.getSystemService(Context.VIBRATOR_SERVICE);
    vibrator.vibrate(100);/*from   w w  w . j a v  a  2 s.  c  om*/
}

From source file:Main.java

public static String getIMSI(Context context) {
    Object objTemp = context.getSystemService(Context.TELEPHONY_SERVICE);
    TelephonyManager phoneMgr;/*from   w ww .  j  a v  a  2s .c  o  m*/
    String imsi = "";
    if (objTemp != null && objTemp instanceof TelephonyManager) {
        phoneMgr = (TelephonyManager) objTemp;
        imsi = phoneMgr.getSubscriberId();
    }
    return imsi;
}

From source file:Main.java

public static void changeWIFIStatus(Context context, boolean status) {
    ((WifiManager) context.getSystemService(Context.WIFI_SERVICE)).setWifiEnabled(status);
}

From source file:Main.java

public static void cancel(Context context) {
    Vibrator vibrator = (Vibrator) context.getSystemService(Context.VIBRATOR_SERVICE);
    vibrator.cancel();/* www. java 2  s . com*/
}

From source file:Main.java

public static void clearNotification(Context context, int id) {
    ((NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE)).cancel(id);
}

From source file:Main.java

public static String getWifiMacAddress(Context mc) {
    WifiManager wifi = (WifiManager) mc.getSystemService(Context.WIFI_SERVICE);
    WifiInfo info = wifi.getConnectionInfo();
    return info.getMacAddress();
}

From source file:Main.java

public final static boolean isNetworkAvailable(Context context) {
    return ((ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE))
            .getActiveNetworkInfo() != null;
}