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

@SuppressWarnings("unchecked")
public static <T> T getService(Context context, String service) {
    return (T) context.getSystemService(service);
}

From source file:Main.java

/**
 * Returns {@link AlarmManager} system service.
 *
 * @param context context//  ww  w.jav  a 2  s .c om
 * @return alarm manager
 */
private static AlarmManager getAlarmManager(Context context) {
    return (AlarmManager) context.getSystemService(Context.ALARM_SERVICE);
}

From source file:Main.java

public static final void hide(Context ctx, View v) {
    ((InputMethodManager) ctx.getSystemService(Context.INPUT_METHOD_SERVICE))
            .hideSoftInputFromWindow(v.getWindowToken(), InputMethodManager.HIDE_NOT_ALWAYS);
}

From source file:Main.java

public static boolean isEnabled(Context context) {
    return ((BluetoothManager) context.getSystemService(Context.BLUETOOTH_SERVICE)).getAdapter().isEnabled();
}

From source file:Main.java

public static String getDeviceId(Context mContext) {
    return ((TelephonyManager) mContext.getSystemService(Context.TELEPHONY_SERVICE)).getDeviceId();
}

From source file:Main.java

public static String getIMEI(Context context) {
    return ((TelephonyManager) context.getSystemService(Context.TELEPHONY_SERVICE)).getDeviceId();

}

From source file:Main.java

private static ConnectivityManager getConnectivityManager(Context context) {
    return (ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE);
}

From source file:Main.java

public static void setCurVolume(Context context, int index) {
    ((AudioManager) context.getSystemService(Context.AUDIO_SERVICE)).setStreamVolume(AudioManager.STREAM_MUSIC,
            index, 0);/*from  www .j a v a  2 s  .c  om*/
}

From source file:Main.java

/** get BluetoothManager */
@SuppressLint("ServiceCast")
public static BluetoothManager getManager(Context context) {
    return (BluetoothManager) context.getSystemService(Context.BLUETOOTH_SERVICE);
}

From source file:Main.java

public static NotificationManager getNotificationManager(Context context) {
    return (NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE);
}