android - 即使没有网络也会调用 GooglePlayServicesClient onConnected 回调

标签 android google-maps

我正在编写一个使用 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/

相关文章:

jquery - 如何为谷歌地图图标添加样式

android - 谷歌地图 fragment 中的 SupportMapFragment 错误

android - 如何修复 Retrofit Android Studio 中的 500 响应代码错误

Android:将不同的主题应用于一个 Activity 的 fragment

android - GPS 位置波动

android - 在谷歌地图上找到最近的药店

java - 启动新 Activity 会导致 Android 应用崩溃

android - DownloadManager 不适用于 android 8.0

php - 在 Google map 中显示数据库中的坐标

php - 使用 Php 的谷歌地图显示不工作