Skip to main content

Screen Flashlight: Building the first app

/galleries/dropbox/android-app.png

So, I finally got an Android-based Acer Liquid S100 (Liquid E, with 512Mb RAM). I've spent some time to get accustomed to the Acer changes to the UI and apps and finally found that I can not use Funambol Sync properly on that device. Acer simply replaced the Contacts application with their own version which does not ask for the application to edit the contact. Basically Funambol Contacts are read-only on that device. So I started looking around to find how android is being built.

Liquid E does not have any flash LED (the only thing I am missing that was in my Nokia 5530). The flashlight is rather important to have so every time I reflashed the device to stock state I had to go to Android Market and pick the simplest app possible. At some moment I realized that I cannot find that application anymore.

How hard is it to build a blank screen/full brightness app?

Manifest:

screenlight/AndroidManifest.xml

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
      package="com.errormessaging.screenlight"
      android:versionCode="1"
      android:versionName="1.0">
    <application android:icon="@drawable/icon"
                 android:label="@string/app_name"
                 android:theme="@android:style/Theme.NoTitleBar.Fullscreen">
        <activity android:name=".ScreenLight"
                  android:label="@string/app_name">
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />
                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
        </activity>
    </application>
</manifest>

The source code goes to src/com/errormessaging/screenlight/ScreenLight.java:

screenlight/ScreenLight.java

package com.errormessaging.screenlight;

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

public class ScreenLight extends Activity {
    /** Called when the activity is first created. */
    @Override
    public void onCreate(Bundle savedInstanceState) {
        WindowManager.LayoutParams lp = getWindow().getAttributes();
        lp.screenBrightness = 1f;
        lp.flags |= WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON;
        getWindow().setAttributes(lp);

        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);
    }
}

That's it.

Source

Full source code for this awesome application is available in Launchpad Bazaar:

bzr branch lp:~rye/+junk/screenlight-android

You can download the compiled Screen Light.apk (signed with debug key) from Ubuntu One.

Comments

Comments powered by Disqus