30 January 2011

Apache ActiveMQ Startup Exception

I don't use ActiveMQ a lot but when I get back to a project where I was using it, I seem to get startup exceptions pretty often.  The stack trace is really long and ugly.

java.io.EOFException: Chunk stream does not exist at page: 0

At first I wasn't sure what was going on, just deleted the activemq folder, unzipped the distro, and back running in minutes.  The next time it happened, I spent a few minutes looking at what I may have done to cause this.


Out of just dumb luck, I found that if I deleted the activemq/data folder contents (not the data folder itself, just the contents - kahadb, localhost, etc), I could restart without error.  Turns out that there's a bug in KahaDB, the default persistence store in ActiveMQ.

I've found no side effects from deleting the data folder contents, none of my deployed apps need to maintain message persistence between shutdowns.

YMMV.

What do you think? Leave a comment.

Android SMS XML Parsing

Using XML with SMS sounds kinda dumb.  After all an SMS text is only 140 characters (or less ...) and XML is horribly bloated.  But if the originating application is using XML and SMS is the convenient transport, then nothing's too stupid.

There's plenty of articles that describe the various Android options for parsing XML.  SAX, DOM, and XML Pull.  Actually, I'd prefer to use XStream for quick XML read/writing but with the XStream jar around 500k, it's not a good droid choice.

I'm going to quickly show you how I intercept incoming SMS messages and route them to an XML parser if the message starts with a tag (in my case <evt>).  After parsing, I then look at fields in the message and then start other processing that I won't go into here.

I'll show you some quick screen shots of the code and attempt to explain.  At the end of the article, you'll find a link to the entire Eclipse project.  This has been tailored down quite a bit from how I'm using it.  It simply sniffs incoming messages and then displays XML fields.

An example incoming XML SMS message looks like this.  I'm receiving XML SMS messages from several sources such as email (like below) and from Twitter (like I blogged about here and here).


Even though my sample SMS XML message shows line breaks so the XML is nicely formated, you don't want to do this.  Don't waste a precious character on a break.  Run all the XML tags together.  My XML Pull Parser class is expecting no line breaks.

In AndroidManifest.xml, add a receiver for the SMS_RECEIVED action to your application and add RECEIVE_SMS to your permissions:


...

In your receiver class (the one that you named in your manifest file), extend BroadcastReceiver and implement onReceive.  After jumping thru a few hoops to get the message content, determine if this is a message you care about.  My "special" messages all have the XML tag "" after a few header characters depending on the source (such as email or Twitter).  If I find this tag, I display a quick toast and then send the message for XML parsing.

 
Here's an example Eclipse app that parses incoming SMS message and checks if they have the tage.  If so, a toast message is displayed and the sent of for XML parsing.  After parsing, the app simply display the contents of a few of the XML tag contents.

My deployed app is actually an Android service, not a simple app like this example.

Download the example.

What do you think? Leave a comment.

28 January 2011

HTC G1 adb "No Permissions"

Update:  After I wrote this post, I had the No permissions and a device name of ???????? all over again.  After spending yet more time on this, I found that the key is to kill and restart the server as root (sudo).  See commands at end of this post.

--------------------------------------------------------
I bought a used HTC G1 from eBay so I could prototype a droid interface to a custom sensor.  I didn't want to brick my daily use DroidX and heard that the G1 had a pretty decent serial interface ability.

I paid a little more than I wanted but those suckers are selling for about $125 which ain't bad (for the seller) for a 2+ year old phone.  After a week or so of bidding, I ended up with a decent condition phone for $83 including shipping.

The phone is locked to T-Mobile and has no sim card but that's okay because I plan to use this as wifi only.  Unfortunately I haven't been able to run the Android Debug Bridge (adb) or use the Android Development Tools (ADT) plugin for Eclipse.

At first I thought my problem with getting the adb "no permission error" was because my phone wasn't activated.



I read thru a few links on how to activate a no sim card phone and decided that it wasn't the issue and needed to keep investigating other causes.

Squirrel.  Before I go into a little more detail, let me share a quick story.  My shiny used G1  didn't come with a USB cable so I bought a cable (also from eBay) for about $1.78 including shipping.  Unfortunately for that screaming deal, it was being shipped from a country far far away.  A few days after I paid (mid January), I received this email:

"we have sent the item you ordered from us today.It would take you 25-35
working days to get it.because of near merry christmas,at the airport were
plied so many package ,plane is not ebough ,every package are slow,hopey
you can understanding ,If you haven't got it within 35 days,please let me
know.,And"

And a week later, my package arrived.  That was a fast 35 days, I guess they found "ebough" planes ...  But the cable didn't work.  I looked at the auction again to make sure that it said it was for a G1.  Sure enough, it states:


USB Sync Data Cord Cable For GOOGLE HTC G1 Android

But in small print, says:


Compatible with: HTC G1(not include the cell phone)

Ok, so what's an HTC G1 that's not a cell phone?


I wasn't going to even waste my time for $1.78 to contact the seller, chalk it up as another buyer beware.


But I did what I should've done next.  Use my leftover unused Blackberry cable.  Fits perfect, charge light goes on and I can mount the G1's SD card. 

Back to the main story.

Besides the "no permissions" error with adb, I can't communicate via the Eclipse plug-in. 




I checked the devices android version to make sure that I had the corresponding SDK platform revision, which I did.

Mr Google yielded some ideas.  One hit suggested that I use sudo with adb.  I don't think that'll help but sure let's try.



Then came across a useful hit Using ADB in Linux that describes that we need to create a file to change permissions and ownership of a device node.  Here's how:

  • Create a file /etc/udev/rules.d/50-android.rules with this command:
sudo gedit /etc/udev/rules.d/51-android.rules
  •  Type in the contents of the file.  The version of linux may cause the syntax to differ slightly.  I'm using Ubuntu 11.04 Natty Narwhal and my contents are in the pic below.


    I've also seen instructions to use this:


    SUBSYSTEMS==”usb”, ATTRS{idVendor}==”0bb4″, ATTRS{idProduct}==”0c01″, MODE=”0666″  

    Note the diff between what I used SUBSYSTEM vs SUBSYSTEMS and ATTRS


    Here's an interesting read on Writing udev Rules.
  •  Change permissions of the file
sudo chmod a+r /etc/udev/rules.d/51-android.rules
  • Restart udev
    sudo restart udev
  • Stop and restart adb
sudo ./adb kill-server
sudo ./adb start-server
  • List the devices

Sweet!


What do you think? Leave a comment.