List of usage examples for android.content Context getSystemService
@SuppressWarnings("unchecked") public final @Nullable <T> T getSystemService(@NonNull Class<T> serviceClass)
From source file:Main.java
public static int getScrWidth(Context context) { WindowManager wm = (WindowManager) context.getSystemService(Context.WINDOW_SERVICE); Display display = wm.getDefaultDisplay(); return display.getWidth(); }
From source file:Main.java
public static int getScreenHeight(Context context) { WindowManager wm = (WindowManager) context.getSystemService(Context.WINDOW_SERVICE); DisplayMetrics metrics = new DisplayMetrics(); wm.getDefaultDisplay().getMetrics(metrics); return metrics.heightPixels; }
From source file:Main.java
public static String getTopActName(Context ctx) { ActivityManager am = (ActivityManager) ctx.getSystemService(Context.ACTIVITY_SERVICE); ComponentName cn = am.getRunningTasks(1).get(0).topActivity; String clsName = cn.getClassName(); return clsName; }
From source file:Main.java
public static boolean isScreenLock(Context context) { KeyguardManager km = (KeyguardManager) context.getSystemService(Context.KEYGUARD_SERVICE); return km.inKeyguardRestrictedInputMode(); }
From source file:Main.java
public static void vibrator(Context context, int msec) { Vibrator vib = (Vibrator) context.getSystemService(Context.VIBRATOR_SERVICE); if (vib != null) { vib.vibrate(msec);// ww w .ja v a2 s .com } }
From source file:Main.java
public static String getDeviceId(Context context) { TelephonyManager tm = (TelephonyManager) context.getSystemService(Context.TELEPHONY_SERVICE); return tm.getDeviceId(); }
From source file:Main.java
/** * Checks if wifi is ON/* w w w . ja v a 2 s. c o m*/ * @param context * @return */ public static boolean isWifiOn(Context context) { WifiManager wifi = (WifiManager) context.getSystemService(Context.WIFI_SERVICE); return wifi.isWifiEnabled(); }
From source file:Main.java
public static boolean isConnected(Context c) { NetworkInfo info = ((ConnectivityManager) c.getSystemService(Context.CONNECTIVITY_SERVICE)) .getActiveNetworkInfo();/*from www.j av a 2 s . c o m*/ return info != null && info.isConnected(); }
From source file:Main.java
public static String getMacAddress(Context context) { WifiManager manager = (WifiManager) context.getSystemService(Context.WIFI_SERVICE); WifiInfo info = manager.getConnectionInfo(); return info.getMacAddress().toString(); }
From source file:Main.java
public static boolean getWifiEnabled(Context context) { WifiManager wifiManager = (WifiManager) context.getSystemService(Context.WIFI_SERVICE); return wifiManager.isWifiEnabled(); }