我正在编写一个使用 Google 定位服务的应用程序。据我了解,当我在 LocationClient
对象上调用 connect()
方法时,实现 GooglePlayServicesClient.ConnectionCallbacks
的对象应该接收onConnected()
回调仅当 LocationClient
成功连接到 Google 的定位服务时。
但是,问题是即使我的手机没有连接到互联网,我也会收到此回调。不知何故,系统一定认为 LocationClient
已成功连接到 Google 的位置服务,即使我的手机没有连接到互联网。
什么给了?
以下是相关的代码 fragment :
@Override
protected void onStart() {
super.onStart();
mLocationClient.connect();
}
@Override
public void onConnected(Bundle bundle) {
Toast.makeText(this, "Connected", Toast.LENGTH_SHORT).show();
}
最佳答案
onConnected
当您的应用程序成功连接到 Google Play 服务应用程序时调用回调方法。您无需连接到互联网即可接收 GPS 更新。
关于android - 即使没有网络也会调用 GooglePlayServicesClient onConnected 回调,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19748629/