2

我想知道如何确定 GPS 的状态,如果状态不同,AVAILABLE我不会创建侦听器来节省电池。

但在执行中,始终输入elsecreate theLocationListener而不是if.

这是我的代码

public class UpdateGPS extends Thread{
    public void run(){
        while (true){
            try{
                getGPS();
                sleep(30000); //Update GPS for each 30secs
            }
            catch(Exception e){}
        }
    }
}

public void getGPS() {
    String state = "RUNNING";
    BlackBerryCriteria myCriteria = new BlackBerryCriteria(GPSInfo.GPS_MODE_ASSIST);
    try {           
    locationProvider = LocationProvider.getInstance(myCriteria);
        if (locationProvider != null) {
            if (locationProvider.getState() != locationProvider.AVAILABLE) {
                state= "STOP";
            }
            else {
                locationProvider.setLocationListener(
                      new LocationListenerImplementacion(),valor_reintento, -1, -1);
            }
        }
    }
    catch(Exception e) {}
} 

private class LocationListenerImplementacion implements LocationListener {
    public void locationUpdated(LocationProvider provider,Location location) {
        if (location.isValid()) {
           //GET DATA
        }
        else {}

    public void providerStateChanged(LocationProvider provider, int newState){

    }

}
4

0 回答 0