Join Now
Quality Rating:
  • Currently 0.0 / 5
(0.0 / 5 - 0 votes cast)
Expertise Level:
  • Currently 0.0 / 5
(0.0 / 5 - 0 votes cast)

This page was last modified 09:47, 28 November 2007.

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

From Forum Nokia Wiki

You know Java ME has many optional packages that phones must have preinstalled over MIDP and CLDC. So, how can you compile one only code that detects on the fly if some class or API is available?

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;
}
 
Powered by MediaWiki
     
     RDF Facets:
     
     
     qfnZtopicQUqfnTopicZjavaQ
     qfnZtypeQUqfnTypeZCommunityContentQ
     qfnZtypeQUqfnTypeZWebpageQ
     qfnZtypeQUqfnTypeZWikiContentQ
     qmarsZlanguageQUxhttpE3aE2fE2fswE2enokiaE2ecomE2flanguageE2d1E2fenX