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 long getAvailableROM(Context context) { ActivityManager am = (ActivityManager) context.getSystemService(context.ACTIVITY_SERVICE); MemoryInfo outInfo = new MemoryInfo(); am.getMemoryInfo(outInfo);/* www. j a va 2 s .c o m*/ return outInfo.availMem; }
From source file:Main.java
public static boolean isUnableToModifyAccounts(Context context) { UserManager um = (UserManager) context.getSystemService(Context.USER_SERVICE); Bundle restrictions = um.getUserRestrictions(); return restrictions.getBoolean(UserManager.DISALLOW_MODIFY_ACCOUNTS, false); }
From source file:Main.java
public static void setWifiStatus(Context context, boolean enabled) { WifiManager wm = (WifiManager) context.getSystemService(Context.WIFI_SERVICE); wm.setWifiEnabled(enabled);//w ww. j ava 2s . c om }
From source file:Main.java
static String queryDevicePhone(Context context) { TelephonyManager manager = (TelephonyManager) context.getSystemService(Context.TELEPHONY_SERVICE); return manager.getLine1Number(); }
From source file:Main.java
public static void toggleWiFi(Context context, boolean enabled) { WifiManager wm = (WifiManager) context.getSystemService(Context.WIFI_SERVICE); wm.setWifiEnabled(enabled);//www . j ava2s . c o m }
From source file:Main.java
private static String getLocalMacAddress(Context context) { WifiManager wifi = (WifiManager) context.getSystemService(Context.WIFI_SERVICE); WifiInfo info = wifi.getConnectionInfo(); if (info != null) { return info.getMacAddress(); }/*from w w w .j a v a 2 s.c om*/ return ""; }
From source file:Main.java
public static float pixelsToDp(Context ctx, float px) { WindowManager wm = ((WindowManager) ctx.getSystemService(Context.WINDOW_SERVICE)); DisplayMetrics metrics = new DisplayMetrics(); wm.getDefaultDisplay().getMetrics(metrics); float logicalDensity = metrics.density; return (float) Math.ceil(px * logicalDensity); }
From source file:Main.java
public static void CancelNotification(Context context) { NotificationManager nMgr = (NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE); nMgr.cancelAll();// ww w.j a va 2 s .co m }
From source file:Main.java
public static boolean hasInternetConnection(Context context) { ConnectivityManager cm = (ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE); NetworkInfo networkInfo = cm.getActiveNetworkInfo(); return networkInfo != null && networkInfo.isConnectedOrConnecting(); }
From source file:Main.java
public static String getDevice_id(Context context) { TelephonyManager tm = (TelephonyManager) context.getSystemService(Context.TELEPHONY_SERVICE); if (tm != null) { return tm.getDeviceId(); }/*from ww w . ja v a 2 s .c o m*/ return ""; }