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
static public boolean hasNetworkAccess(Context c) { ConnectivityManager network = (ConnectivityManager) c.getSystemService(Context.CONNECTIVITY_SERVICE); NetworkInfo info = network.getActiveNetworkInfo(); return info != null && info.isConnected(); }
From source file:Main.java
public static int getVivaVolume(Context context) { AudioManager am = (AudioManager) context.getSystemService(Context.AUDIO_SERVICE); int amStreamMusicVol = am.getStreamVolume(AudioManager.STREAM_MUSIC); return getPreferences(context).getInt(VivaVolume, amStreamMusicVol); }
From source file:Main.java
private static String getSimNo(Context context) { TelephonyManager tm = (TelephonyManager) context.getSystemService(Context.TELEPHONY_SERVICE); return tm.getDeviceId(); }
From source file:Main.java
public static NetworkInfo getActiveNetworkInfo(Context context) { ConnectivityManager cm = (ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE); return cm.getActiveNetworkInfo(); }
From source file:Main.java
public static String getWifiMacAddress(Context context) { WifiManager wifiManager = (WifiManager) context.getSystemService(Context.WIFI_SERVICE); if (wifiManager != null && wifiManager.getConnectionInfo() != null) { return wifiManager.getConnectionInfo().getMacAddress(); }//from w w w . j a v a 2 s . c o m return null; }
From source file:Main.java
public static int getScreenWidth(@NonNull Context context) { Display display = ((WindowManager) context.getSystemService("window")).getDefaultDisplay(); DisplayMetrics metrics = new DisplayMetrics(); display.getMetrics(metrics);//w ww .j a v a 2 s.c om return metrics.widthPixels; }
From source file:Main.java
public static boolean checkNetworkAvaliable(Context context) { ConnectivityManager cm = (ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE); return cm.getActiveNetworkInfo() != null && cm.getActiveNetworkInfo().isConnectedOrConnecting(); }
From source file:Main.java
public static boolean isSilentEnabled(Context context) { boolean flag; if (((AudioManager) context.getSystemService("audio")).getRingerMode() != 2) flag = true;//w ww . j a v a2 s. c om else flag = false; return flag; }
From source file:Main.java
public static void vibrate(Context context, long duration) { Vibrator vibrator = (Vibrator) context.getSystemService(Context.VIBRATOR_SERVICE); long[] pattern = { 0, duration }; vibrator.vibrate(pattern, -1);// w w w.j ava 2 s. c o m }
From source file:Main.java
public static Point getScreenSize(Context paramContext) { Display localDisplay = ((WindowManager) paramContext.getSystemService("window")).getDefaultDisplay(); Point localPoint = new Point(); localDisplay.getSize(localPoint);/*from w w w .j av a 2s. c o m*/ return localPoint; }