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!

Gist, GitHub and Live Writer

Microsoft has a small project they purchased with some company that is actually very nice – small, free and better than most commercial products – Live Writer http://windowslivewriter.spaces.live.com . Supports different blogging sites, has many nice features. All in all – a solid product.

It also supports a very simple plugin model for easy extensibility of the program.

As you might have noticed before, I am posting snippets of code using a most excellent http://gist.github.com service.

So I decided to make a plugin for Live Writer that will simplify that process. 20 minutes of work and it is done. You can find it at the Live Writer Extension Gallery. The sources (badly written due to laziness) can be downloaded here.

2010/06/24

Detecting network availability on Android

This tip is not really a ‘hidden feature’, but it’s useful and can come in handy if you don’t want to register BroadcastReceiver and add listeners for network events, but just want to check if you have network access at a certain point.

2010/06/23

Transparent UIWebView on iPhone

Here's a little trick that allows you to create a WebView in your iPhone application that has it's background transparent, showing whatever controls you have underneath.
Could be used to create some sort of animation/background images behind the view.

2010/06/20

Shaking on the iPhone

Let’s say you have an iPhone application with many different View Controllers, and in some of them you want to detect a ‘Device Shake’ event. You can’t just catch it in the Controller itself, since it provide methods for that. So the solution is this – you subclass a UIWindow to detect an event and then broadcast it to your app. Then catch the event in appropriate places using NSNotificationCenter.

Don’t forget to change the parent class of your main Window to MotionWindow to catch the events.

Enjoy, here's the code:

 

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!




2010/06/14

Set Sail

During my many hours of laboring as a mobile application developer I came across an interesting fact - the amount of documentation provided to the programmers by the different OS manufacturers is incredibly scarce and partial, missing many small details that can cause countless hours of hear-pulling and cursing.

Thankfully we now have sites like StackOverflow which connect developers and empower them, but even there you sometimes miss this important information.

So I present to you, dear Internet, this blog, in which I will some times post notes, code snippets, suggestions and findings that I believe can be useful to many developers word wide.

P.S. I do not claim the be the uber-specialist, nor do I claim copyright for the code. It's been either collected from pieces on the net, or glued together by me.
You are free to use and repost anything you find here, though I would appreciate a mention in you comments if you plan on using the content.