Tuesday, June 18, 2013

Android ADB devices offline

Most of the solutions found on the internet ask you to kill and restart adb server.

adb kill-server
adb start-server

unplug and plug in the mobile phone
uncheck and check the usb debugging option

This does not fix my problem.

Android 4.2.2 has a new security feature where user has to confirm the RSA signature of the computer before it is allowed to connect to the phone. Old version of ADB does not support this feature and will always show your device as offline.

Solution:-
1. Check your adb version and where your adb command points to, on my case, there is an older version of adb at /usr/bin.
adb version
Android Debug Bridge version 1.0.29

type -a adb
/usr/bin/adb

2. Delete the old adb and fastboot. Ubuntu's apt-get installed the outdated version.

cd /usr/bin
sudo rm fastboot
sudo rm adb

3. Download ADT/SDK from http://developer.android.com.
4. Update your system PATH and points to the updated adb

gedit .bashrc (ubuntu, replace with any other text editor you like)
add this to the last line of the file

export PATH=$PATH:...../adt-bundle-linux-x86_64-20130522/sdk/platform-tools (please replace it with the path to the sdk you downloaded)

5. Check your version again

type -a adb
.../adt-bundle-linux-x86_64-20130522/sdk/platform-tools/adb

adb version
Android Debug Bridge version 1.0.31

6. Plug in your phone and enjoy!

Sunday, April 21, 2013

Ambient Lighting Monitor with Android and Java

Fascinated by Arduino and Raspberry Pi recently. Found a cool application called "Ambient Lighting" which calculates the light on your monitor and changes the color of the LED accordingly. The effect is real time cinema-like movie watching experience.

Note that this video is stolen from http://brunql.github.io/ambilight/


Most of them are using LED with Arduino controller. None of the people think of using the screen of the mobile phone or tablet as a light source (they are probably too dim for the desired effect which I found out later).

This is a quick hack during the weekend, firstly take a screenshot of the current screen. It was easier than I thought using the Java built-in function of java.awt.Robot, createScreenCapture(). After that get all the Red, Green and Blue of each pixels and calculate the average color for the current screen. Ratios of the color according to the different positions such as main color on the top right or bottom left portion of the screen are ignored as my light source is limited (1 or 2 android phone) and could not display different color on each spot.

After that, I need a simple way to send the color data to the android phone. I got lazy and just use Simple Framework to serve HTTP response on configured port. For example, every time the phone send request to http://my_ip:7788, it would return the calculated average color for current screen. To make it easier, I return a simple HTML code to set the background color of the whole page with the calculated RGB value. The page will reload every 1 second using HTTP "META refresh" tag. Reload the page more frequently with javascript should result in a more realistic ambient lighting.

The result is less satisfactory than had been anticipated. The screen of the mobile phone is not as bright as expected even after manually tuning it to the maximum brightness. Probably can improve the effect after tuning the calculated color to make it look brighter. Position information should make multiple phones and tablets act as the "LED", albeit much more expensive. Just for the sake of fun as I have a couple of Android devices hanging around.

I have published the code on bitbucket and feel free to have a look if you are looking to waste some time to enhance your movie watching experience. =)

My code on bitbucket
Ambient light

Reference:
http://brunql.github.io/ambilight/
https://code.google.com/p/boblight/
https://code.google.com/p/light-pack/
http://learn.adafruit.com/adalight-diy-ambient-tv-lighting/download-and-install