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

/**  ------------------------------------------------------------------------  Phone Calls -- */

public static boolean deviceCanMakePhoneCall(final Context context) {
    if (((TelephonyManager) context.getSystemService(Context.TELEPHONY_SERVICE)).getLine1Number() == null) {
        // no phone
        return false;
    }/*from   ww  w .j  av a2s . co m*/
    return true;
}

From source file:Main.java

public static boolean isGpsEnabled(Context context) {
    LocationManager lm = (LocationManager) context.getSystemService(Context.LOCATION_SERVICE);
    return lm.isProviderEnabled(LocationManager.GPS_PROVIDER);
}

From source file:Main.java

public static boolean isWifiEnabled(Context context) {
    WifiManager wifiManager = (WifiManager) context.getSystemService(Context.WIFI_SERVICE);
    return wifiManager.isWifiEnabled();
}

From source file:Main.java

public static void setClip(Context context, CharSequence text) {
    ((ClipboardManager) context.getSystemService(Context.CLIPBOARD_SERVICE))
            .setPrimaryClip(ClipData.newPlainText("", text));
}

From source file:Main.java

public static int getScreenWidth(Context context) {
    WindowManager wm = (WindowManager) context.getSystemService(Context.WINDOW_SERVICE);
    DisplayMetrics displayMetrics = new DisplayMetrics();
    wm.getDefaultDisplay().getMetrics(displayMetrics);
    return displayMetrics.widthPixels;
}

From source file:Main.java

/**
 * Gets instance of BluetoothManager.//from w  w  w .j av a2s.c om
 * @param context context of application
 * @return Instance of BluetoothManager or null if the BluetoothManager does not exist.
 */
public static BluetoothManager getManager(final Context context) {
    return (BluetoothManager) context.getSystemService(Context.BLUETOOTH_SERVICE);
}

From source file:Main.java

public static boolean checkGPS(Context context) {
    LocationManager lm = (LocationManager) context.getSystemService(Context.LOCATION_SERVICE);
    boolean GPS_status = lm.isProviderEnabled(LocationManager.GPS_PROVIDER);
    return GPS_status;
}

From source file:Main.java

public static ConnectivityManager getConnManager(Context context) {
    return (ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE);
}

From source file:Main.java

public static void KeyVibrate(final Context context) {
    Vibrator vib = (Vibrator) context.getSystemService(Service.VIBRATOR_SERVICE);
    vib.vibrate(100);//from   w ww .  jav  a  2 s  .c om
}

From source file:Main.java

public static void copyToClipboard(String content, Context context) {
    ClipboardManager cmb = (ClipboardManager) context.getSystemService(Context.CLIPBOARD_SERVICE);
    cmb.setText(content.trim());/*from   ww  w  . j a  v a  2 s  . c  o m*/
}