【问题标题】:HaveGooglePlayServices and OnConnected拥有 GooglePlayServices 和 OnConnected
【发布时间】:2016-07-17 00:47:50
【问题描述】:

我目前正在尝试访问 GooglePlayServices。

我最近发现了另一种访问 GooglePlay 服务的方法,这次是通过 OAuth 2.0。我还从 gitHub 中找到了一个示例,其中显示了如何使用它的示例。

https://github.com/google/google-api-java-client-samples/blob/master/tasks-android-sample/src/main/java/com/google/api/services/samples/tasks/android/TasksSample.java

但是,我对新方法有点困惑,特别是从哪里开始发送请求。

我正在尝试使用 Google Play 客户端访问一个人的位置,但我不确定将 locationRequest 的开头放在哪里。使用 GoogleAPIClient 时,开始是在 onConnected 中。

但是,在我发现的这个具体示例中,没有任何东西可以接近这一点。最接近的是:

  private void haveGooglePlayServices() {
    if (credential.getSelectedAccountName() == null) {
      chooseAccount();
    } else {
      // This is where I think I need to start sending requests.
      AsyncLoadTasks.run(this);
    }
  }

(sn-p 是第 197 到 206 行)

这个假设是否正确,还是需要我在其他地方开始发送位置请求?

【问题讨论】:

    标签: java android


    【解决方案1】:

    中编写你的代码
    onConnected(Bundle connectionhint)
    

    这样

     @Override
    public void onConnected(Bundle connectionHint) {
        mLastLocation = LocationServices.FusedLocationApi.getLastLocation(
                mGoogleApiClient);
        if (mLastLocation != null) {
            mLatitudeText.setText(String.valueOf(mLastLocation.getLatitude()));
            mLongitudeText.setText(String.valueOf(mLastLocation.getLongitude()));
        }
    }
    

    或查看link

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2015-11-13
      相关资源
      最近更新 更多