There is no API that enable a Java ME developer to access the flight mode. The key here is to get a system property via the right key, no pun intended :) This is done via a call to
System.getProperty("key")
. The key differs from platform to platform.On a Motorola mobile phone, with Motorola OS, this is done like this:
String airplaneMode = System.getProperty("com.mot.network.airplanemode");
if(airplaneMode.equals("true")){
// We are in flight mode
}else{
// We are not in flight mode
}
On a Sony Ericsson mobile phone it is a little bit different, since there is no system property to detect if we are in flight mode or not. The trick here is to use a key that detects the Radio Access Technology (RAT) used at the moment. This returns null if the radio is turned of, which it always is when in flight mode. The code looks like this:
String flightMode = System.getProperty("com.sonyericsson.net.rat");
if(flightMode == null){
// We are in flight mode
}else{
// We are not in flight mode
}
And that is it! Pretty simple, but still powerful. I hope this trick is useful for you.
No comments:
Post a Comment