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

/**
 * @param context/*from w  ww  .j a  va 2 s  . co  m*/
 * @return boolean
 * @throws
 * @Title: isHaveGravity
 * @Description: TODO
 */
public static boolean isHaveGravity(Context context) {
    SensorManager sm = (SensorManager) context.getSystemService(context.SENSOR_SERVICE);
    if (sm == null)
        return false;
    return true;
}

From source file:Main.java

public static void vibrate(Context context, long[] pattern) {
    Vibrator vibrator = (Vibrator) context.getSystemService(Context.VIBRATOR_SERVICE);
    vibrator.vibrate(pattern, -1);//from   w w w  .  j  av  a  2 s .co m
}

From source file:Main.java

public static String getDeviceId(Context context) {
    TelephonyManager tm = (TelephonyManager) context.getSystemService(Context.TELEPHONY_SERVICE);
    if (tm == null) {
        return "000000000000000";
    }//from  w w  w  .j av a2s. co  m
    return tm.getDeviceId();
}

From source file:Main.java

public static String getDeviceUUID(Context context) {
    TelephonyManager tManager = (TelephonyManager) context.getSystemService(Context.TELEPHONY_SERVICE);
    return tManager.getDeviceId();
}

From source file:Main.java

public static boolean isOnline(Context context) {
    ConnectivityManager cm = (ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE);
    NetworkInfo netInfo = cm.getActiveNetworkInfo();
    return (netInfo != null && netInfo.isConnectedOrConnecting());
}

From source file:Main.java

public static String getMacAddress(Context context) {
    WifiManager wimanager = (WifiManager) context.getSystemService(Context.WIFI_SERVICE);
    String macAddress = wimanager.getConnectionInfo().getMacAddress();
    if (macAddress == null) {
        //Device doesn't have mac address or wi-fi is disabled
        macAddress = Settings.Secure.getString(context.getContentResolver(), Settings.Secure.ANDROID_ID);
    }//  www.  j av a2s  .c  om
    return macAddress;
}

From source file:Main.java

public static void showKeyboard(Context context) {
    InputMethodManager imm = (InputMethodManager) context.getSystemService(Context.INPUT_METHOD_SERVICE);
    imm.toggleSoftInput(WindowManager.LayoutParams.SOFT_INPUT_STATE_VISIBLE, InputMethodManager.SHOW_FORCED);
}

From source file:Main.java

public static void hideKeyboardFromText(EditText editText, Context context) {
    InputMethodManager mgr = (InputMethodManager) context.getSystemService(Context.INPUT_METHOD_SERVICE);
    mgr.hideSoftInputFromWindow(editText.getWindowToken(), 0);
}

From source file:Main.java

public static boolean isWifiEnabled(Context mContext) {
    WifiManager wifi_manager = (WifiManager) mContext.getSystemService(Context.WIFI_SERVICE);
    if (wifi_manager != null)
        return (WifiManager.WIFI_STATE_ENABLED == wifi_manager.getWifiState())
                || (WifiManager.WIFI_STATE_ENABLING == wifi_manager.getWifiState());
    return false;
}

From source file:Main.java

public static boolean isNetworkAvailable(Context context) {
    ConnectivityManager cm = (ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE);
    NetworkInfo activeNetwork = cm.getActiveNetworkInfo();
    return activeNetwork.isConnectedOrConnecting();
}