Namespaces
Variants
Actions

How to detect if a Class/Package is available on the phone

Jump to: navigation, search

This article shows how to determine at runtime whether a particular optional Java ME class or API is available on the device.

SignpostIcon Gear 52.png
Article Metadata

Article
Created: firt (15 Apr 2007)
Last edited: hamishwillee (24 Jan 2012)

We can use the dynamic instantiation method, like this:

boolean MMAPIAvailable;
try {
// Try to instantiate a class using a string as the Class name
// so, the SDK without the API can compile the application
Class.forName("javax.microedition.media.Player").newInstance();
// If the next code is executed, then the API is available
MMAPIAvailable = true;
} catch ( ClassNotFoundException e) {
MMAPIAvailable = false;
}
This page was last modified on 24 January 2012, at 06:28.
64 page views in the last 30 days.
Nokia Developer aims to help you create apps and publish them so you can connect with users around the world.

京ICP备05048969号  © Copyright Nokia 2013 All rights reserved