来自IntentService的Android Awareness Snapshot API出现错误7503

时间:2017-04-08 16:50:05

标签: android intentservice google-awareness

我有一个IntentService,其工作是从Google Awareness API更新Weather数据,然后将其传递给Wear伴侣。

我获得了API密钥,获得了位置权限,当代码从一个简单的Activity调用时,一切正常。 (在我的mainActivity中,它是相同的代码,在IntentService中,它位于相同的包中,在同一个应用程序中)。

代码:

function getVarsities() {
  $query = "SELECT * FROM `tb_university`";

  $result = mysqli_query($this - > link, $query);

  if ($result) {


    echo "<option>Select University</option>";
    while ($row = mysqli_fetch_array($result, MYSQLI_ASSOC)) {
      $VarsityName = $row['university_name'];

      echo "<option>$VarsityName</option>";
    }

  } else {
    echo "record not found";
  }
}

function getFaculties($ff) {
  $uni_id = 0;
  $query = "SELECT `university_id` FROM `tb_university` WHERE `university_name` = '$ff'";
  $result = mysqli_query($this - > link, $query);
  if ($result) {
    while ($row = mysqli_fetch_array($result, MYSQLI_ASSOC)) {
      $uni_id = $row['university_id'];
    }


  }
  $query1 = "SELECT `faculty_name` FROM `faculty` WHERE `university_id` = $uni_id";
  $result1 = mysqli_query($this - > link, $query1);
  if ($result1) {
    while ($row = mysqli_fetch_array($result1, MYSQLI_ASSOC)) {
      $fal_name = $row['faculty_name'];
      echo < option > $fal_name < /option>;
    }
  }
}

所以,这段代码给我的状态确定,并在活动中传递正确的天气数据。

代码是ACL_ACCESS_DENIED。 位置已启用,获得了权限。

在GoogleApiClient.Builder中尝试了“this”,“getApplicationContext”,“getBaseContext”,“getApplication”。他们都没有工作。

有人有解决方案吗?

编辑: 这是IntentService的相关代码。但它类似于我写的上层代码:

if (ActivityCompat.checkSelfPermission(this, android.Manifest.permission.ACCESS_FINE_LOCATION) != PackageManager.PERMISSION_GRANTED) {
        ActivityCompat.requestPermissions(this, new String[]{android.Manifest.permission.ACCESS_FINE_LOCATION}, 0);
    }
    mGoogleApiClient = new GoogleApiClient.Builder(this, new GoogleApiClient.ConnectionCallbacks() {
        @Override
        public void onConnected(@Nullable Bundle bundle) {
            if (ActivityCompat.checkSelfPermission(MainActivity.this, android.Manifest.permission.ACCESS_FINE_LOCATION) != PackageManager.PERMISSION_GRANTED) {
                return;
            }
            Awareness.SnapshotApi.getWeather(mGoogleApiClient).setResultCallback(new ResultCallback<WeatherResult>() {
                @Override
                public void onResult(@NonNull WeatherResult weatherResult) {
                    Log.w("a", "result:" + weatherResult.getStatus().toString());
                    if (weatherResult.getStatus().isSuccess())
                    {
                        Log.w("a", "Weather:" + weatherResult.getWeather().toString());
                    }
                }
            });
        }

        @Override
        public void onConnectionSuspended(int i) {

        }
    }, new GoogleApiClient.OnConnectionFailedListener() {
        @Override
        public void onConnectionFailed(@NonNull ConnectionResult connectionResult) {

        }
    }).addApi(Awareness.API).build();
    mGoogleApiClient.connect();

}

0 个答案:

没有答案