2
我使用GoogleApiClient监听启动时启动的服务上的位置,通过侦听android.intent.action.BOOT_COMPLETED的BroadcastReceiver。GoogleApiClient在启动时未连接服务
@Override
public void onReceive(Context context, Intent intent) {
Intent serviceA = new Intent(context, ServiceA.class);
startWakefulService(context, serviceA);
}
在服务使用:
mGoogleApiClient = new GoogleApiClient.Builder(ServiceB.this)
.addConnectionCallbacks(mConnectionCallbacks)
.addOnConnectionFailedListener(mOnConnectionFailedListener)
.addApi(LocationServices.API).build();
mGoogleApiClient.connect();
服务在系统启动开始,但我的问题是,无论是mConnectionCallbacks也不mOnConnectionFailedListener是不断调用。
我在做什么有什么问题。当我在“活动”或“活动”启动的服务上使用它时,这种方式可以很好地调用GoogleApiClient。
谢谢
涉及到的位置也方法依赖的NetworkInfo?这将在离线时起作用吗? – buzoherbert
@buzoherbert这个方法是由android官方推荐的https://github.com/googlesamples/android-play-location/tree/master/BasicLocationSample它基于Google playservice。我使用网络信息来检查互联网连接是否存在。你可以忽略它...谢谢 –
谢谢,但是这不能解决我的问题。我有相同的实现,但在启动时启动的服务。这就是它不起作用的地方。 – buzoherbert