OK, I suggest you run it on your test device in the foreground, and monitor what happens. Maybe it's throwing an exception somewhere.
You have a tendancy to catch exceptions and swallow the silently, which may be causing you to miss useful information.
One thing I recommend you change is the connection code. Make sure the connection is closed after you use it.
PHP Code:
SecureConnection sc = (SecureConnection) Connector.open("ssl://our-server-address", Connector.WRITE);
try {
sc.setSocketOption(SocketConnection.LINGER, 0);
sc.setSocketOption(SocketConnection.KEEPALIVE, 0);
OutputStream os = sc.openOutputStream();
try {
os.write(request.getBytes());
os.write(0);
os.flush();
} finally {
os.close();
}
} finally {
sc.close();
}
Rather than catching exceptions and ignoring them, I'd suggest you let them propagate up the code, to a point where you can decide whether it's safe to ignore them, where you can handle them (for example, by re-trying an operation), or where you can report them (or log them to RMS, for example). Avoid returning 0, -1, false or null to indicate an error condition; that's what exceptions are for.
PHP Code:
public static Coordinates getLocation(int timeout) throws LocationException, InterruptedException {
Criteria cr = new Criteria();
cr.setPreferredPowerConsumption(Criteria.POWER_USAGE_MEDIUM);
LocationProvider provider = LocationProvider.getInstance(cr);
Location location = provider.getLocation(timeout);
Coordinates c = location.getQualifiedCoordinates();
return c;
}
Avoid catching "Exception", catch the actual type you intend to handle or ignore (except as a "catch all" at the highest level of the program).
Make use of finally{} to release resources like connections, RecordStores and so on. Remember you can have a finally{} without a catch{}.
Cheers,
Graham.