JSR 179 API exception on JavaFX on WIndows Mobile 6.1/5 Devices
943140Jun 12 2012 — edited Jun 13 2012I have a generic Java application which gets GPS coordinates from the mobile device using JSR 179 API calls. This Java app is developed using JavaME 3.0 SDK and runs on JavaFX JVM .This app is developed using generic Java APIs so that it can be run on various mobile devices with various operating systems.
However this app does not get the GPS coordinates on certain Windows Mobile 6.1/6.5 devices and fails with “ All providers are out of service “ exception.
I debugged the issue by enabling logs in the microsoft dll- Gpsapi.dll and found that only dll attach is happening for gpsapi.dll when the app is launched and no other gpsapi function (GPSOpen device and GPSGetposition etc )is being invoked by the java app running on javafx jvm. These apis have to be invoked to actually retrieve the GPs coordinates.
How can I get the JSR 179 location api to work on Windows mobile devices? The GPS midlet code is :
public class GPSMidlet extends MIDlet implements LocationListener, CommandListener
{
private static final String APP_NAME = "Location Services";
private static final Command exitCommand = new Command("Exit", Command.EXIT, 2);
private Display display;
private Form form;
private LocationProvider locationProvider;
public GPSMidlet() {
this.display = Display.getDisplay(this);
this.form = new Form(APP_NAME);
this.form.addCommand(exitCommand);
this.form.append(new StringItem(null, "MIDlet started @ " + new Date(System.currentTimeMillis())));
this.form.setCommandListener(this);
}
protected void destroyApp(boolean arg0) throws MIDletStateChangeException {
destroyLocationProvider();
notifyDestroyed();
}
protected void pauseApp() {}
protected void startApp() throws MIDletStateChangeException {
initializeLocationProvider();
this.display.setCurrent(this.form);
}
public void locationUpdated(LocationProvider arg0, Location location) {
if(location != null){
form.deleteAll();
form.append(new StringItem(null, ("Location updated on " + new Date(location.getTimestamp()).toString())));
form.append(new StringItem(null, dumpLocation(location)));
if(location.getAddressInfo() != null)
form.append(new StringItem("", dumpAddressInfo(location.getAddressInfo())));
if(location.getQualifiedCoordinates() != null)
form.append(new StringItem(null, dumpCoordinates(location.getQualifiedCoordinates())));
}
}
public void providerStateChanged(LocationProvider arg0, int state) {
this.form.append(new StringItem(null, ("Location provider state has changed to: " + state)));
}
public void commandAction(Command cmd, Displayable arg1) {
if(cmd.equals(exitCommand)){
try {
this.destroyApp(false);
} catch (MIDletStateChangeException e) {
System.out.println(e.getMessage());
}
}
}
private String dumpLocation(Location location){
StringBuffer buf = new StringBuffer();
buf.append("LOCATION_METHOD=" + location.getLocationMethod());
buf.append("\nSPEED=" + location.getSpeed());
buf.append("\nCOURSE=" + location.getCourse());
return buf.toString();
}
private String dumpAddressInfo(AddressInfo info){
StringBuffer buf = new StringBuffer();
buf.append("\nSTREET=" + info.getField(AddressInfo.STREET));
buf.append("\nCITY=" + info.getField(AddressInfo.CITY));
buf.append("\nSTATE=" + info.getField(AddressInfo.STATE));
buf.append("\nPOSTAL_CODE=" + info.getField(AddressInfo.POSTAL_CODE));
buf.append("\nCOUNTRY=" + info.getField(AddressInfo.COUNTRY));
return buf.toString();
}
private String dumpCoordinates(QualifiedCoordinates qc){
StringBuffer buf = new StringBuffer();
buf.append("\nLATITUDE=" + qc.getLatitude());
buf.append("\nLONGITUDE=" + qc.getLongitude());
buf.append("\nALTITUDE=" + qc.getAltitude());
buf.append("\nHORIZONTAL_ACCURACY=" + qc.getHorizontalAccuracy());
buf.append("\nVERTICAL_ACCURACY=" + qc.getVerticalAccuracy());
return buf.toString();
}
private void initializeLocationProvider(){
try {
this.locationProvider = LocationProvider.getInstance(null);
}
catch (LocationException e) {
e.printStackTrace();
String s = e.toString();
form.append(s);
form.append(new StringItem(null, "Error acessing location provider"));
}
if(this.locationProvider != null){
this.locationProvider.setLocationListener(this, -1, 5, -1);
}
}
private void destroyLocationProvider(){
if (this.locationProvider != null) {
this.locationProvider.setLocationListener(null, -1, 5, -1);
}
}
}