Showing posts with label blackberry. Show all posts
Showing posts with label blackberry. Show all posts

2010/07/05

Bitmap Button in Blackberry

I won't bitch about the state of Blackberry UI framework, just mention that there's isn't a standard button class that supports images. WTF?
In any case, here's the code that implements one.

2010/06/26

Inter-process Communication of BlackBerry

Maybe I just don’t know how to read the docs, or how to Google, but I was looking for this info way too much, somehow it was burried. In any case – let’s say you have to apps on the device, and they use a common PersistenStore. One app adds stuff there in the background. The other – shows a UI with a list of the items from the store. All nice and synchronized. The only problem is – there is no way to detect that the PersistentObject that you are using was updated! So if you want to have your list refreshed automatically – you have to get creative.

On the producer side, after updating the PersistentStore, post a global notification with a unique ID:
ApplicationManager.getApplicationManager().postGlobalEvent(Main.NOTIFICATIONS_ID_1);

On the consumer side (UI), register for the notifications, then catch that message and update the UI accordingly:

Why I Hate BlackBerry. Also, how to make a folder.

Let’s be clear, RIM should be ashamed of the way their developer toolkit looks. The documentation is sparse at best, their own ide JDE looks and works like something from the 70s, and their Eclipse plugin refuses to work with actual devices and crashes on Simulator hot swaps. I am not even mentioning the fact that the UI has to be built in code like in the DOS days. Seriously? No GUI builders? In 2010? Sheesh. Now to the tip of today: How to make a folder on a SD Card.

Sounds simple right? Open a FileConnection, call a mkdir() method? Nope. IO Exceptions, Cannot access root file system and other not very helpful messages (all that is in addition to the fact that you cannot work with both debugger and SD card at the same time. very convenient).

Basically, the hidden gem is – you must have a trailing slash at the end of your path. Otherwise – no mkdir() for you!

2010/06/16

Get your Blackberry app version programmatically

Let's say you want to add a 'About' dialog in your application and you want to show current application's version.

Sounds easy, right? Well, not exactly. In BlackBerry there could be several apps per COD file, called ‘modules’, so you have to traverse them to find your own module. Then there’s the case with simulators which are not close to the real device and therefore cause many issues, so you have to add a special case for them… All this sums up to the following piece of code:



2010/06/15

Sending an SMS on BlackBerry

While reading documentation on SMS sending in BlackBerry JDE JavaDocs you come across a fact that several important parts are missing.
Documentation mentions SMS 'port', a number you are supposed to write after the phone, using the :123 format. Googling, you might see on many sites a random number provided, then on others you see a + sign used in the phone number.
Don't believe the hype!
Here's a simple function, that, given a phone number (just digits) and SMS text, will simply send a SMS or return false in case something bad happens. Easy peasy!