As already said in another thread
1) trying to load JSR-specific class is safe and *reliable* way to detect JSR support presence in a device
2) of course having you main class implementing JSR-specific interface is not good - put the JSR-specific code into a separate class (no imports there still advisable), detect JSR-support presence (eg in the main class), and call the helper class only if it's ok
try {
Class clazz = Class.forName("javax.microedition.location.LocationProvider");
jsr179 = true;
} catch (ClassNotFoundException e) {
}
...
if (jsr179) {
"use helper class in some way"
}
...
Helper class for JSR-specific code:
Code:
public class Jsr179Stuff {
private javax.microedition.location.LocationProvider impl;
public Jsr179LocationProvider() {
impl = javax.microedition.location.LocationProvider.getInstance(null);
impl.setLocationListener(new StuffListener, ...);
...
}
private class StuffListener implements implements javax.microedition.location.LocationListener {
// fullfill contract here
}
}