为Fused location API添加addGpsStatusListener

时间:2015-09-06 20:55:30

标签: android wear-os android-fusedlocation

我已添加:

implements GoogleApiClient.ConnectionCallbacks, LocationListener, GpsStatus.Listener

        mGoogleApiClient = new GoogleApiClient.Builder(context)
            .addApi(LocationServices.API)
            .addApi(Wearable.API)
            .addConnectionCallbacks(this)
            .build();
    mGoogleApiClient.connect();

    locationManager = (LocationManager) context.getSystemService(Context.LOCATION_SERVICE);
    locationManager.addGpsStatusListener(this);

@Override
public void onGpsStatusChanged(int event) {
    Log.d(TAG, "GPS status change: " + event);

    switch(event) {
        case GpsStatus.GPS_EVENT_FIRST_FIX:                        
            break;                                          
        case GpsStatus.GPS_EVENT_SATELLITE_STATUS:
            break;
    }
}

但是没有为Fused Location API调用onGpsStatusChanged。这可能吗?

1 个答案:

答案 0 :(得分:0)

这对我来说很好。我能够在onGpsStatusChanged()方法中接收事件。如果你想查看我的代码。

我正在使用以下版本

的游戏服务的gradle依赖性
compile 'com.google.android.gms:play-services-location:8.4.0'

用工具

class FusedLocationProviderService extends Service implements 
        GpsStatus.Listener, 
        LocationListener,
        GoogleApiClient.ConnectionCallbacks,
        GoogleApiClient.OnConnectionFailedListener,
        ResultCallback<LocationSettingsResult> {

    public void initialize() {
         googleApiClient = new GoogleApiClient.Builder(context)
                            .addConnectionCallbacks(this)
                            .addOnConnectionFailedListener(this)
                            .addApi(LocationServices.API).build();

         locationManager = (LocationManager) context
                        .getSystemService(LOCATION_SERVICE);

         locationManager.addGpsStatusListener(this);
    }
}