【问题标题】:Add addGpsStatusListener for the Fused location API为 Fused location API 添加 addGpsStatusListener
【发布时间】:2015-12-02 09:25:55
【问题描述】:

我已添加:

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;
    }
}

但融合位置 API 不会调用 onGpsStatusChanged。这可能吗?

【问题讨论】:

  • 没有。我为 Wear 制作了一个应用程序,因此我在移动端添加了一个服务,并使用没有融合位置的普通 GPS API(以获取 onGpsStatusChanged)。然后与 Wear 通信(在 Wear 方面,我仍然使用 Fused location API,即两者的混合)。

标签: android wear-os android-fusedlocation


【解决方案1】:

它对我来说很好用。我能够在 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);
    }
}

【讨论】:

  • 你在 Wear 设备上试过了吗?
猜你喜欢
  • 2018-01-15
  • 1970-01-01
  • 2016-04-07
  • 2016-07-09
  • 2015-05-16
  • 2017-05-04
  • 2016-04-09
  • 2015-08-17
  • 2019-09-04
相关资源
最近更新 更多