Tuesday, April 23, 2013

Enabling Android Logcat on a Huawei Smartphone

Getting your debug to work on a Huawei smartphone is a bit tricky, since the LogCat is disabled by default for (useless) security reasons.

First of all, to enable the LogCat you must take all the usual steps to debug an Android app on a real device under Eclipse. Then, you must take the following further steps to get the work done:


  1. on the smartphone press the number *#*#2846579#*#* which will show you a secret menu, quite common to find on android devices;
  2. choose ProjectMenu >> Background setting >> Log setting;
  3. now you will see 2 entries: "Log switch" and "Log level setting"; just choose the second one to set the minimum debugging level shown and confirm on the popup dialog, then choose "Log ON" on the first entry and confirm again;
  4. reboot the device.

Connect the Huawei to your PC via USB and... ta-daa! Eclipse will show you the LogCat.

Have fun!

Thursday, January 31, 2013

Connecting an Android App to a Tomcat Localhost

While working on the development of an Android client for one of our web apps we ran into the task of connecting our client app to a java servlet running on a local instance of Tomcat under Eclipse.

It was then that we realized that the standard way to connect to localhost or 127.0.0.1 didn't work with Android at all.

The reason is that both an AVD emulator and a real Android device will interpret the localhost as the machine which is running the app, that is, the Android emulator/device itself.

So, if you are trying to make your Android app to connect to a java servlet (or any web app) running on Tomcat under Eclipse, you must:

  1. change the IP part of the URL you're trying to connect to 10.0.2.2 (http://127.0.0.1:8080/myapp/myservlet become http://10.0.2.2:8080/myapp/myservlet for example) as explained in  the official Android documentation.
  2. if (1) for some reason it doesn't work, try setting the IP address of the machine which is running Eclipse as the IP part of the servlet URL; you can get it by running ipconfig under the start >> execute on Windows-based OSs.
  3. if (1) and (2) won't work, try to close and restart Eclipse.
  4. if none of the solutions above will work, man, it can only be a bug in your networking source code; debug it carefully and then try the previous steps again.

Just to be clear, this is only for testing purposes on localhost: restore the original URL address to connect to before to deploy your Android app or it won't work.

Have fun!