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 String getCarrierName(Context ctxt) {
    TelephonyManager manager = (TelephonyManager) ctxt.getSystemService(Context.TELEPHONY_SERVICE);
    return manager.getNetworkOperatorName();
}

From source file:Main.java

public static boolean getWifiStatus(Context ctx) {
    WifiManager wifiManager = (WifiManager) ctx.getSystemService(Context.WIFI_SERVICE);
    WifiInfo wifiInfo = wifiManager.getConnectionInfo();
    int state = wifiInfo.getNetworkId();
    return state != -1;
}

From source file:Main.java

public static int getScreenDensityDpi(Context context) {
    WindowManager wm = (WindowManager) context.getSystemService(Context.WINDOW_SERVICE);
    DisplayMetrics outMetrics = new DisplayMetrics();
    wm.getDefaultDisplay().getMetrics(outMetrics);
    return outMetrics.densityDpi;
}

From source file:Main.java

public static int getMaxVolume(Context context) {
    AudioManager manager = (AudioManager) context.getSystemService(Context.AUDIO_SERVICE);
    int max = manager.getStreamMaxVolume(AudioManager.STREAM_MUSIC);

    return max;/* ww w .  j a  v a 2 s. c  o  m*/
}

From source file:Main.java

public static int getCallState(Context context) {
    TelephonyManager tm = (TelephonyManager) context.getSystemService(Context.TELEPHONY_SERVICE);
    return tm.getCallState();
}

From source file:Main.java

public static long getAvailMem(Context context) {
    ActivityManager am = (ActivityManager) context.getSystemService(Context.ACTIVITY_SERVICE);
    ActivityManager.MemoryInfo memoryInfo = new ActivityManager.MemoryInfo();
    am.getMemoryInfo(memoryInfo);//w ww .  ja  v a2s  .  c om
    return memoryInfo.availMem;
}

From source file:Main.java

public static String getMobileNumber(Context context) {
    TelephonyManager t = (TelephonyManager) context.getSystemService(context.TELEPHONY_SERVICE);
    String number = t.getLine1Number();
    return number;
}

From source file:Main.java

/**
 * Get the constant describing the rotation of the screen.
 *
 * @param context//from ww  w.  j  av  a2 s. c o  m
 * @return
 */
public static int getDisplayRotation(Context context) {
    WindowManager wm = (WindowManager) context.getSystemService(Context.WINDOW_SERVICE);
    return wm.getDefaultDisplay().getRotation();
}

From source file:Main.java

public static int getPhoneType(Context context) {
    TelephonyManager tm = (TelephonyManager) context.getSystemService(Context.TELEPHONY_SERVICE);
    return tm.getPhoneType();
}

From source file:Main.java

public static String getAppDeviceId(Context context) {
    TelephonyManager tm = (TelephonyManager) context.getSystemService(Context.TELEPHONY_SERVICE);
    String deviceId = tm.getDeviceId();
    return deviceId;
}