Friday, January 27, 2012

Dell pc suite troubles adb

I suddenly started to have a lot of problems connecting my device to adb.

I was pretty frequently getting this error

** daemon still not running error: cannot connect to daemon


I restarted computer, restarted the device (Samsung galaxy SII)... but no luck.

In the end it turned out, Dell pc suite was causing some problem. And that explains why I suddenly I started to get this problem.. coz I recently installed dell pc suite for my Dell streak.

I uninstalled Dell PC Suite.. and voila!! No more problems!

Thursday, January 5, 2012

HTTP Delete

We needed a api from our server team to remove a few resources in one shot. The server guy implemented a http DELETE rest api, and to support multiple resource removal in one shot, he decided to take the resource ids in the payload.

But one thing he missed, http protocol does not specify that there can be payload in the delete method. (and it's no more a REST api if it contains payload in delete, right?)

Looks like some http implementations in fact allows payload and that's why in his test, there was no problem.

But when I tried to request that from Android, voila... exception telling DELETE cannot write.


Thursday, December 1, 2011

Hauwei IDEOS adb driver


It was a little bit tricky to install the driver on windows, because I could not find any OEM driver from Hauwei. However, with it can be added as an Android Composite ADB interface easily.

To do that, first make sure you have download Google provided driver.


  1. Launch the SDK and AVD Manager by double-clicking SDK Manager.exe, at the root of your SDK directory.
  2. Expand the Third party Add-ons and Google Inc. add-ons.
  3. Check Google Usb Driver package and click Install selected.
  4. Proceed to install the package. When done, the driver files are downloaded into the <sdk>\extras\google\usb_driver\directory.
Once you have the driver, go to <sdk>\extras\google\usb_driver\ and add the following lines to android_winusb.inf. Make sure to create a backup of the inf file first.


;Huawei IDEOS
%SingleAdbInterface%        = USB_Install, USB\VID_12D1&PID_1038
%CompositeAdbInterface%     = USB_Install, USB\VID_12D1&PID_1038&MI_01

So basically it looked like following as I added the lines after Google nexus one 



;Google NexusOne
%SingleAdbInterface%        = USB_Install, USB\VID_18D1&PID_0D02
%CompositeAdbInterface%     = USB_Install, USB\VID_18D1&PID_0D02&MI_01
%SingleAdbInterface%        = USB_Install, USB\VID_18D1&PID_4E11
%CompositeAdbInterface%     = USB_Install, USB\VID_18D1&PID_4E12&MI_01
%CompositeAdbInterface%     = USB_Install, USB\VID_18D1&PID_4E22&MI_01
;Huawei IDEOS
%SingleAdbInterface%        = USB_Install, USB\VID_12D1&PID_1038
%CompositeAdbInterface%     = USB_Install, USB\VID_12D1&PID_1038&MI_01


[USB_Install]
Include = winusb.inf
Needs   = WINUSB.NT


[USB_Install.Services]
Include     = winusb.inf
AddService  = WinUSB,0x00000002,WinUSB_ServiceInstall



That's it! Now just give this driver location for the IDEOS...
In details for Windows 7:

To install the Android USB driver on Windows 7 for the first time:
  1. Connect your Android-powered device to your computer's USB port.
  2. Right-click on Computer from your desktop or Windows Explorer, and select Manage.
  3. Select Devices in the left pane.
  4. Locate and expand Other device in the right pane.
  5. Right-click the device name (such as Nexus S) and select Update Driver Software. This will launch the Hardware Update Wizard.
  6. Select Browse my computer for driver software and click Next.
  7. Click Browse and locate the USB driver folder. (The Google USB Driver is located in <sdk>\extras\google\usb_driver\.)
  8. Click Next to install the driver.

Thursday, November 10, 2011

RMI Registry port may be used error

I have got a new (a bit more powerful) workstation and was installing everything there. I started downloading all new versions of the tools that I have been using, like new Eclipse, JDK 1.7 etc.

Then when I ran Nokia S40 5th edition emulator, I go this error:

The internal RMI registry port 1099 may be in use by another application.




I tried to change the port, killed all other java apps, but no luck.

In the end, the problem turned out to be a jdk/jre bug. Apparently, the bug surfaced since 1.6 u 29. Here is the bug report. in sdk release note.

So switching to older JDK should fix the problem. I uninstalled jdk and installed JDK1.6 update 23 and it's working fine now!

Friday, November 4, 2011

Android code coverage

Unit tests are definitely a programmer's good friend (when done properly), watching the back and confirming that everything is working alright.

Code coverage is a friend of the unit tests, telling unit tests how well he has covered up his friend.

Anyways, I will give a quick and short instruction here about android unit testing.

Guess what? This is really simple if you have ever written any unit tests before for Java apps. It's all the same

  • First step, create a separate project for unit testing. When you create this project in Eclipse, eclipse will ask you to point to the existing project that you are going to test.
  • Write some unit tests. You will create test cases by extending AndroidTestCase class
  • Run the test, and see if the test method is actually being executed or not. Tests will be run in the emulator / device like a normal app, and will notify to eclipse. Use Eclipse > Show View > JUnit to see the result. There are notes about it in the same link I mentioned above.
  • Now getting the coverage report could not be any simpler:
    • create the ant script for building the test project. Open command prompt and go to your test project directory:
      • android update test-project -m <your_main_project_full_path> -p .
    • and run
      • ant coverage
Done!!!
Look for the coverage directory under test project and a nice report it waiting there.

Now if you are running in windows you may get this error
 "<something like File or SDK > was unexpected at this time.", 
then ant could not find some path. I hate windows "Programs Files" directory, cause that contains a space and space is an enemy for ant. So try Installing your sdk in a path that does not contain any space, and that should resolve it.



Wednesday, October 26, 2011

Verify jad signature

Because midlet signing works a little bit differently, you need to use jadtool to verify the signature:

java -jar %wtk_home%/bin/jadtool.jar -showcert -certnum 1 -inputjad myJadFile.jad

Output of this will be something like:


Subject: C=US, ST=CA, L=Santa Clara, O=dummy CA, OU=JCT, CN=thehost
Issuer : C=US, ST=CA, L=Santa Clara, O=dummy CA, OU=JCT, CN=thehost
Serial number: 3d3ece8a
Valid from Wed Jul 24 08:58:02 PDT 2002 to Sat Jul 21 08:58:02 PDT 2012
Certificate fingerprints:
MD5: 87:7f:5e:64:c8:dd:b4:bf:35:39:76:87:99:9b:68:82
SHA: 9d:c0:88:ce:08:83:cd:e6:fe:13:8b:26:f6:b4:df:e2:da:3c:25:98
To show all certificate details:
java -jar %wtk_home%/bin/jadtool.jar -showcert  -all -inputjad <input_jadfile>

Tuesday, October 18, 2011

LWUIT scrolling problem

LWUIT scrolling works most of the times, however, I had problems with scrolling in a view like this:

I had some non-focusable multiline text area at the bottom of the screen and pressing down when focus is on cancel button did not scroll it.

There may be a better fix, but my quick (and dirty) fix was that, I added a focusable invisible item at the bottom !


    this.setLayout(new BoxLayout(BoxLayout.Y_AXIS));

    Component invisibleItem = createInvisibleItem();

    this.addComponent(input1);
    this.addComponent(input2);
    this.addComponent(buttonOk);
    this.addComponent(buttonCancel);
    this.addComponent(textAreaLong);
this.addComponent(invisibleItem); buttonCancel.setNextFocusDown(invisibleItem); } private void createInvisibleItem() { Component component = new Container(); component.setNextFocusDown(component); //to protect any jump }