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

public static InputMethodManager getInputMethodManager(Context context) {
    return (InputMethodManager) context.getSystemService(Context.INPUT_METHOD_SERVICE);
}

From source file:Main.java

public static String getDisplayClassName(Context context) {
    return ((ActivityManager) context.getSystemService(Context.ACTIVITY_SERVICE)).getRunningTasks(1)
            .get(0).topActivity.getClassName();
}

From source file:Main.java

public static boolean isOnPause(Context ctx) {
    AudioManager am = (AudioManager) ctx.getSystemService(Context.AUDIO_SERVICE);
    return am.getMode() != AudioManager.MODE_NORMAL;
}

From source file:Main.java

public static String getSimOperatorName(Context context) {
    return ((TelephonyManager) context.getSystemService(Context.TELEPHONY_SERVICE)).getSimOperatorName();
}

From source file:Main.java

public static int getMemoryClass(final Context context) {
    return ((ActivityManager) context.getSystemService(Context.ACTIVITY_SERVICE)).getMemoryClass();
}

From source file:Main.java

public static void setVolumeUnmute(Context mc) {
    AudioManager am = (AudioManager) mc.getSystemService(Context.AUDIO_SERVICE);
    am.setStreamMute(AudioManager.STREAM_MUSIC, false);
}

From source file:Main.java

public static void vibrate(Context context) {
    Vibrator v = (Vibrator) context.getSystemService(Context.VIBRATOR_SERVICE);
    if (v.hasVibrator()) {
        v.cancel();/*from w w w  .j a  va2s. co  m*/
        v.vibrate(150);
    }
}

From source file:Main.java

public static AudioManager getAudioManager(Context context) {
    return (AudioManager) context.getSystemService(Context.AUDIO_SERVICE);
}

From source file:Main.java

public static void setVolumeMute(Context mc) {
    AudioManager am = (AudioManager) mc.getSystemService(Context.AUDIO_SERVICE);
    am.setStreamMute(AudioManager.STREAM_MUSIC, true);
}

From source file:Main.java

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