Wakey Droid


While developing Android applications, I discovered that I didn't like to leave my device on continuously. On the other hand I was worried about the power button, as being pressed 30 or more times a day would quickly wear it out. So I developed Wakey Droid ([Google play link|https://play.google.com/store/apps/details?id=bdjnk.android.wakeydroid|Wakey Droid]) to solve this issue.

All you need is for ADB to be properly installed on your computer, and Wakey Droid to be installed on your android device. Then you can issue the command adb -d shell am start -a android.intent.action.MAIN -n bdjnk.android.wakeydroid/.Wakey and your device should wake up. Finally, you can tie this in to some nice shortcut to make it convenient.

This is a very simple application. Although it has become slightly more complex in this second version, it remains simple enough that the entire source code follows:

Wakey.java

package bdjnk.android.wakeydroid;

import android.app.Activity;
import android.os.Bundle;
import android.os.Handler;
import android.view.Window;
import android.view.WindowManager;

public class Wakey extends Activity {

    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);

        Window window = getWindow();
        window.addFlags(WindowManager.LayoutParams.FLAG_SHOW_WHEN_LOCKED
                | WindowManager.LayoutParams.FLAG_TURN_SCREEN_ON
                | WindowManager.LayoutParams.FLAG_DISMISS_KEYGUARD);

        setContentView(R.layout.main);

        Handler handler = new Handler(); 
        handler.postDelayed(new Runnable() { 
             public void run() {
                 Wakey.this.finish();
             } 
        }, 200);
    }
}

AndroidManifest.xml

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="bdjnk.android.wakeydroid"
    android:versionCode="3"
    android:versionName="2.0" >
    <uses-sdk android:minSdkVersion="5" android:targetSdkVersion="15" />
    <application
        android:icon="@drawable/ic_launcher"
        android:label="@string/app_name"
        android:theme="@android:style/Theme.Black.NoTitleBar" >
        <activity
            android:name=".Wakey"
            android:label="@string/app_name"
            android:exported="true"
            android:launchMode="singleInstance"
            android:finishOnTaskLaunch="true"
            android:stateNotNeeded="true"
            android:noHistory="false"
            android:excludeFromRecents="true"/>
    </application>
</manifest>

strings.xml

<?xml version="1.0" encoding="utf-8"?>
<resources>
    <string name="app_name">WakeyDroid</string>
</resources>

main.xml

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:background="@color/black" >
</LinearLayout>

color.xml

<?xml version="1.0" encoding="UTF-8"?>
<resources>
    <color name="black">#ff000000</color>
</resources>

This will work on any device with Eclair (2.0) or greater, and it should bypass any unsecured lock-screens. Suggestions are welcome.