views:

25

answers:

1

What is the right way of working with optional APIs in Java Mobile?

  • Does one need to make different versions of their app?
  • Or is it enough to check APIs availability at runtime using System.getProperty()?

Let's say I'd like my app to support JSR-256 (the Sensor API). Would importing classes from javax.microedition.sensor and registering variables of these types break my app if the device doesn't support it?

I am sure there must be a pretty standard way of handling that situation.

Thanks!

+2  A: 

You can use system properties, or Class.forName() to see if the API is available. Just make sure classes using those APIs don't get loaded on handsets that don't support them. You can make one version of your midlet that supports many different handsets.

funkybro
Right, thanks!Now, sorry for the _stupid_ question. How can I make sure these classes _don't_ get loaded? Should I use them in a separate class that gets loaded if the API is available?Thanks!
Albus Dumbledore
I found it: http://www.developer.com/java/other/article.php/10936_2248831_2/Java-Class-Loading-The-Basics.htm Thanks!
Albus Dumbledore