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 boolean isApplicationBroughtToBackground(Context context) {
    List list = ((ActivityManager) context.getSystemService("activity")).getRunningTasks(1);
    boolean flag;
    if (!list.isEmpty() && !((android.app.ActivityManager.RunningTaskInfo) list.get(0)).topActivity
            .getPackageName().equals(context.getPackageName()))
        flag = true;//from   ww  w  .  j av a2  s .  c  om
    else
        flag = false;
    return flag;
}

From source file:Main.java

public static final boolean isScreenOn(Context context) {
    PowerManager powerManager = (PowerManager) context.getSystemService(Context.POWER_SERVICE);
    return powerManager.isScreenOn();
}

From source file:Main.java

public static String getTopActivity2(Context ctx) {
    ActivityManager am = (ActivityManager) ctx.getSystemService(Context.ACTIVITY_SERVICE);
    List<ActivityManager.RunningTaskInfo> taskInfo = am.getRunningTasks(1);
    Log.d("topActivity", "CURRENT Activity ::" + taskInfo.get(0).topActivity.getClassName());
    ComponentName componentInfo = taskInfo.get(0).topActivity;
    return componentInfo.getPackageName();
}

From source file:Main.java

public static final void Alarm_service(Context ctx, long atTime, Class<?> cls) {
    ((AlarmManager) ctx.getSystemService(Context.ALARM_SERVICE)).set(AlarmManager.RTC_WAKEUP, atTime,
            PendingIntent.getService(ctx, 0, new Intent(ctx, cls), 0));
}

From source file:Main.java

public static String getLocalMacAddress1(Context context) {
    WifiManager wifi = (WifiManager) context.getSystemService(Context.WIFI_SERVICE);
    WifiInfo info = wifi.getConnectionInfo();
    if (info != null) {
        return info.getMacAddress();
    }/*from   ww  w .  j  av  a2  s.  c  om*/
    return null;
}

From source file:Main.java

public static void enableMulticastLock(Context context) {
    WifiManager wifiManager = (WifiManager) context.getSystemService(Context.WIFI_SERVICE);
    MulticastLock multicastLock = wifiManager.createMulticastLock("multicast.test");
    multicastLock.acquire();/*from ww  w  .  ja  v  a2  s  .c  om*/
}

From source file:Main.java

public static String GetDeviceID(Context context) {
    TelephonyManager mngr = (TelephonyManager) context.getSystemService(Context.TELEPHONY_SERVICE);
    return mngr.getDeviceId();
}

From source file:Main.java

@SuppressWarnings("deprecation")
public static int getDeviceWidth(Context context) {
    WindowManager manager = (WindowManager) context.getSystemService(Context.WINDOW_SERVICE);
    return manager.getDefaultDisplay().getWidth();
}

From source file:Main.java

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

From source file:Main.java

public static void showInputMethodPicker(Context context) {
    ((InputMethodManager) context.getSystemService(Context.INPUT_METHOD_SERVICE)).showInputMethodPicker();
}