Skip to content

Instantly share code, notes, and snippets.

@JakeWharton
Created February 7, 2015 01:59

Revisions

  1. JakeWharton created this gist Feb 7, 2015.
    14 changes: 14 additions & 0 deletions gistfile1.java
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,14 @@
    /**
    * 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!
    */
    public static void riseAndShine(Activity activity) {
    activity.getWindow().addFlags(FLAG_SHOW_WHEN_LOCKED);

    PowerManager power = (PowerManager) activity.getSystemService(POWER_SERVICE);
    PowerManager.WakeLock lock =
    power.newWakeLock(FULL_WAKE_LOCK | ACQUIRE_CAUSES_WAKEUP | ON_AFTER_RELEASE, "wakeup!");
    lock.acquire();
    lock.release();
    }