List of usage examples for android.content Context POWER_SERVICE
String POWER_SERVICE
To view the source code for android.content Context POWER_SERVICE.
Click Source Link
From source file:Main.java
public static PowerManager.WakeLock acquireLock(Context context) { if (wakeLock == null || !wakeLock.isHeld()) { PowerManager powerManager = (PowerManager) context.getSystemService(Context.POWER_SERVICE); wakeLock = powerManager.newWakeLock(PowerManager.PARTIAL_WAKE_LOCK, "TT"); wakeLock.setReferenceCounted(true); wakeLock.acquire();// w w w .j a v a 2 s . co m } return wakeLock; }
From source file:Main.java
/** * Wake ups the phone./* w w w . j a va2s . co m*/ * @param context */ public static void partialWakeUpLock(Context context) { PowerManager pm = (PowerManager) context.getApplicationContext().getSystemService(Context.POWER_SERVICE); PowerManager.WakeLock wakeLock = pm.newWakeLock((PowerManager.SCREEN_BRIGHT_WAKE_LOCK | PowerManager.FULL_WAKE_LOCK | PowerManager.ACQUIRE_CAUSES_WAKEUP), "TAG"); wakeLock.acquire(); }
From source file:Main.java
private static boolean isScreenOffOrLocked(Context context) { KeyguardManager keyguardManager = (KeyguardManager) context.getSystemService(Context.KEYGUARD_SERVICE); PowerManager powerManager = (PowerManager) context.getSystemService(Context.POWER_SERVICE); boolean off = !powerManager.isScreenOn(); off |= keyguardManager.inKeyguardRestrictedInputMode(); return off;/* ww w .j a v a2s . com*/ }
From source file:Main.java
/** * @return Whether the screen of the device is interactive. */// w ww .j a va 2s. co m @SuppressWarnings("deprecation") public static boolean isInteractive(Context context) { PowerManager manager = (PowerManager) context.getSystemService(Context.POWER_SERVICE); if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT_WATCH) { return manager.isInteractive(); } else { return manager.isScreenOn(); } }
From source file:Main.java
/** * Hold wake lock./*from w w w .j a va 2 s.c o m*/ * * @param context * the context */ public static void holdWakeLock(Context context) { PowerManager powerManager = (PowerManager) context.getSystemService(Context.POWER_SERVICE); wakeLock = powerManager.newWakeLock(PowerManager.PARTIAL_WAKE_LOCK, "MyWakeLock"); wakeLock.acquire(); }
From source file:Main.java
public static void acquireTemporaryWakelocks(Context context, long timeout) { if (wakeLock == null) { PowerManager powerManager = (PowerManager) context.getSystemService(Context.POWER_SERVICE); wakeLock = powerManager.newWakeLock(PowerManager.PARTIAL_WAKE_LOCK | PowerManager.ACQUIRE_CAUSES_WAKEUP | PowerManager.ON_AFTER_RELEASE, "PushSMS"); }// w w w. j ava 2 s . co m wakeLock.acquire(timeout); if (wifiLock == null) { WifiManager wifiManager = (WifiManager) context.getSystemService(Context.WIFI_SERVICE); wifiLock = wifiManager.createWifiLock("PushSMS"); } wifiLock.acquire(); new Handler().postDelayed(new Runnable() { @Override public void run() { wifiLock.release(); } }, timeout); }
From source file:Main.java
/** * Show the activity over the lockscreen and wake up the device. If you * launched the app manually both of these conditions are already true. If * you deployed from the IDE, however, this will save you from hundreds of * power button presses and pattern swiping per day! *//*w ww . j a va 2s . c om*/ public static void riseAndShine(Activity activity) { activity.getWindow().addFlags(WindowManager.LayoutParams.FLAG_SHOW_WHEN_LOCKED); PowerManager power = (PowerManager) activity.getSystemService(Context.POWER_SERVICE); PowerManager.WakeLock lock = power.newWakeLock( PowerManager.FULL_WAKE_LOCK | PowerManager.ACQUIRE_CAUSES_WAKEUP | PowerManager.ON_AFTER_RELEASE, "wakeup!"); lock.acquire(); lock.release(); }
From source file:Main.java
public static boolean isScreenLight(Context context) { PowerManager pm = (PowerManager) context.getSystemService(Context.POWER_SERVICE); return pm.isScreenOn(); }
From source file:Main.java
public static void setWakeLock(Context context) { PowerManager pm = (PowerManager) context.getSystemService(Context.POWER_SERVICE); wl = pm.newWakeLock(PowerManager.FULL_WAKE_LOCK | PowerManager.ACQUIRE_CAUSES_WAKEUP, TAG); wl.acquire();/* w w w. j a v a 2s . c om*/ }
From source file:org.traccar.client.WakefulBroadcastReceiver.java
public static void startWakefulForegroundService(Context context, Intent intent) { synchronized (mActiveWakeLocks) { int id = mNextId; mNextId++;// w w w . j av a2 s . c o m if (mNextId <= 0) { mNextId = 1; } intent.putExtra(EXTRA_WAKE_LOCK_ID, id); ContextCompat.startForegroundService(context, intent); PowerManager pm = (PowerManager) context.getSystemService(Context.POWER_SERVICE); PowerManager.WakeLock wl = pm.newWakeLock(PowerManager.PARTIAL_WAKE_LOCK, WakefulBroadcastReceiver.class.getSimpleName()); wl.setReferenceCounted(false); wl.acquire(60 * 1000); mActiveWakeLocks.put(id, wl); } }