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 String getIMSI(Context context) { TelephonyManager tm = (TelephonyManager) context.getSystemService(Context.TELEPHONY_SERVICE); String imsi = tm.getSubscriberId(); return imsi;/* www . j a v a 2 s. co m*/ }
From source file:Main.java
public static void toggleSoftInput(Context context) { InputMethodManager imm = (InputMethodManager) context.getSystemService(Context.INPUT_METHOD_SERVICE); imm.toggleSoftInput(InputMethodManager.SHOW_FORCED, InputMethodManager.HIDE_IMPLICIT_ONLY); }
From source file:Main.java
public static boolean isOnWifi(Context context) { WifiManager lWifiManager = (WifiManager) context.getSystemService(Context.WIFI_SERVICE); return lWifiManager == null ? false : lWifiManager.isWifiEnabled() && lWifiManager.getConnectionInfo() != null && lWifiManager.getConnectionInfo().getIpAddress() != 0; }
From source file:Main.java
public static int getWifiState(Context context) { WifiManager wifiManager = (WifiManager) context.getSystemService(Context.WIFI_SERVICE); if (wifiManager != null) { return wifiManager.getWifiState(); }// w w w . j a v a 2 s . co m return WifiManager.WIFI_STATE_DISABLED; }
From source file:Main.java
public static int getScreenWidth(Context context) { WindowManager wm = (WindowManager) context.getSystemService(Context.WINDOW_SERVICE); Display display = wm.getDefaultDisplay(); DisplayMetrics metrics = new DisplayMetrics(); display.getMetrics(metrics);// ww w . j a v a 2 s .com return metrics.widthPixels; }
From source file:Main.java
private static void getScreenMetric(Context cxt) { WindowManager wm = (WindowManager) cxt.getSystemService(Context.WINDOW_SERVICE); Display display = wm.getDefaultDisplay(); Point size = new Point(); display.getSize(size);/*from w w w .j a va 2s. c o m*/ mScreenWidth = size.x; mScreenHeight = size.y; }
From source file:Main.java
public static String getSubscriberId(Context context) { TelephonyManager tm = (TelephonyManager) context.getSystemService(Context.TELEPHONY_SERVICE); String tel = tm.getSubscriberId(); return TextUtils.isEmpty(tel) ? "" : tel; }
From source file:Main.java
public static String getPhoneMac(Context context) { WifiManager wifi = (WifiManager) context.getSystemService(Context.WIFI_SERVICE); WifiInfo info = wifi.getConnectionInfo(); return info.getMacAddress(); }
From source file:Main.java
public static String getDeviceID(Context context) { TelephonyManager mngr = (TelephonyManager) context.getSystemService(Context.TELEPHONY_SERVICE); String deviceID = mngr.getDeviceId(); return deviceID; }
From source file:Main.java
public static String getIPAddress(Context context) { WifiManager wifiManager = (WifiManager) context.getSystemService(Context.WIFI_SERVICE); int ipAddress = wifiManager.getConnectionInfo().getIpAddress(); return String.format("%d.%d.%d.%d", (ipAddress & 0xff), (ipAddress >> 8 & 0xff), (ipAddress >> 16 & 0xff), (ipAddress >> 24 & 0xff)); }