Skip to content

Instantly share code, notes, and snippets.

@jdsingh
Forked from billmote/AndroidManifest.xml
Created June 8, 2016 19:34
Show Gist options
  • Save jdsingh/a1dc22d858cfae0ebdf180abaf434d23 to your computer and use it in GitHub Desktop.
Save jdsingh/a1dc22d858cfae0ebdf180abaf434d23 to your computer and use it in GitHub Desktop.
When pushing code from your IDE, wake the device and show the activity.

WAKEUP!

How many times a day do you push code to your phone and then pick it up, press the power button to wake the device and then swipe to unlock? If you're like me that answer is probably hundreds!

By adding a couple of permissions to your src/debug/AndroidManifest.xml file and adding a helper class in src/debug/... that can be called from your activities, you can wakeup and unlock the device automatically when you push code to your phone.

<?xml version="1.0" encoding="utf-8"?>
<!-- Add this as a debug manifest so the permissions won't be required by your production app -->
<manifest xmlns:android="http://schemas.android.com/apk/res/android">
<uses-permission android:name="android.permission.WAKE_LOCK" />
<uses-permission android:name="android.permission.DISABLE_KEYGUARD" />
</manifest>
public class BaseActivity extends Activity {
@Override
protected void onStart() {
super.onStart();
// Wake the device and show our activity
if (BuildConfig.DEBUG) {
// Calling this from your launcher activity is enough, but I needed a good example spot ;)
DebugUtils.riseAndShine(this);
}
}
}
import android.app.Activity;
import android.app.KeyguardManager;
import android.os.PowerManager;
import static android.content.Context.KEYGUARD_SERVICE;
import static android.content.Context.POWER_SERVICE;
import static android.os.PowerManager.ACQUIRE_CAUSES_WAKEUP;
import static android.os.PowerManager.FULL_WAKE_LOCK;
import static android.os.PowerManager.ON_AFTER_RELEASE;
import static android.view.WindowManager.LayoutParams.FLAG_SHOW_WHEN_LOCKED;
/**
* Add this to your application's src/debug/... sources
*/
public class DebugUtils {
/**
* 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) {
KeyguardManager keyguardManager = (KeyguardManager) activity.getSystemService(KEYGUARD_SERVICE);
final KeyguardManager.KeyguardLock keyguardLock = keyguardManager.newKeyguardLock("Unlock!");
keyguardLock.disableKeyguard();
activity.getWindow().addFlags(FLAG_SHOW_WHEN_LOCKED);
PowerManager powerManager = (PowerManager) activity.getSystemService(POWER_SERVICE);
PowerManager.WakeLock wakeLock = powerManager.newWakeLock(FULL_WAKE_LOCK | ACQUIRE_CAUSES_WAKEUP | ON_AFTER_RELEASE, "Wakeup!");
wakeLock.acquire();
wakeLock.release();
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment