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 float getScreenWeigh(Context context) {
    windowManager = (WindowManager) context.getSystemService(Context.WINDOW_SERVICE);
    return windowManager.getDefaultDisplay().getWidth();
}

From source file:Main.java

public static void copyToClipboard(Context context, String text) {
    ((ClipboardManager) context.getSystemService(Context.CLIPBOARD_SERVICE)).setText(text);
}

From source file:Main.java

public static boolean isWifiConnect(Context paramContext) {
    return ((ConnectivityManager) paramContext.getSystemService("connectivity")).getNetworkInfo(1)
            .isConnected();//from   www.j  av  a 2  s  .com
}

From source file:Main.java

public static final int audioVolume(Context ctx) {
    AudioManager audio = (AudioManager) ctx.getSystemService(Context.AUDIO_SERVICE);
    return audio.getStreamVolume(AudioManager.STREAM_RING);
}

From source file:Main.java

public static void vibration(Context context) {
    Vibrator vibrator = (Vibrator) context.getSystemService(Context.VIBRATOR_SERVICE);
    vibrator.vibrate(100);// w  w w  .ja v a  2s  .  c o m
}

From source file:Main.java

public static final void audioModeSilent(Context ctx) {
    AudioManager audio = (AudioManager) ctx.getSystemService(Context.AUDIO_SERVICE);
    audio.setRingerMode(AudioManager.RINGER_MODE_SILENT);
}

From source file:Main.java

public static final void audioModeVibrate(Context ctx) {
    AudioManager audio = (AudioManager) ctx.getSystemService(Context.AUDIO_SERVICE);
    audio.setRingerMode(AudioManager.RINGER_MODE_VIBRATE);
}

From source file:Main.java

public static int isTabletDevice(Context paramContext) {
    if (((TelephonyManager) paramContext.getSystemService("phone")).getPhoneType() == 0)
        ;//from  w  w w . j  a  v a 2 s.  c  om
    for (int i = 1;; i = 0)
        return i;
}

From source file:Main.java

public static void stopExtraMusic(Context context) {
    AudioManager am = (AudioManager) context.getSystemService(Context.AUDIO_SERVICE);
    am.requestAudioFocus(null, AudioManager.STREAM_MUSIC, AudioManager.AUDIOFOCUS_GAIN_TRANSIENT);
}

From source file:Main.java

public static void resumeExtraMusic(Context context) {
    AudioManager am = (AudioManager) context.getSystemService(Context.AUDIO_SERVICE);
    am.abandonAudioFocus(null);/*  ww  w . j ava2  s  .co  m*/
}