Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/199.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
来自IntentService的Android感知快照API出现错误7503_Android_Intentservice_Google Awareness - Fatal编程技术网

来自IntentService的Android感知快照API出现错误7503

来自IntentService的Android感知快照API出现错误7503,android,intentservice,google-awareness,Android,Intentservice,Google Awareness,我得到了一个IntentService,它的工作是从Google Awareness API更新天气数据,并将其传递回Wear companion 我得到了API密钥,获得了位置权,当代码从一个简单的活动调用时,一切都正常。 (在我的mainActivity中,代码与IntentService中的代码相同,它位于同一个包中,在同一个应用程序中) 代码: if(ActivityCompat.checkSelfPermission(this,android.Manifest.permission.A

我得到了一个IntentService,它的工作是从Google Awareness API更新天气数据,并将其传递回Wear companion

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

代码:

if(ActivityCompat.checkSelfPermission(this,android.Manifest.permission.ACCESS\u FINE\u LOCATION)!=PackageManager.permission\u已授予){
ActivityCompat.requestPermissions(这个新字符串[]{android.Manifest.permission.ACCESS\u FINE\u LOCATION},0);
}
mGoogleApiClient=new-GoogleApiClient.Builder(这是new-GoogleApiClient.ConnectionCallbacks()){
@凌驾
未连接的公共无效(@Nullable Bundle){
if(ActivityCompat.checkSelfPermission(MainActivity.this,android.Manifest.permission.ACCESS\u FINE\u LOCATION)!=PackageManager.permission\u已授予){
返回;
}
Awareness.SnapshotApi.getWeather(mGoogleApiClient.setResultCallback(new-ResultCallback()){
@凌驾
public void onResult(@NonNull WeatherResult WeatherResult){
Log.w(“a”,“result:+weatherResult.getStatus().toString());
if(weatherResult.getStatus().isSuccess())
{
Log.w(“a”,“Weather:+weatherResult.getWeather().toString());
}
}
});
}
@凌驾
公共空间连接暂停(int i){
}
},新的GoogleAppClient.OnConnectionFailedListener(){
@凌驾
public void onconnection失败(@NonNull ConnectionResult ConnectionResult){
}
}).addApi(Awareness.API).build();
mGoogleApiClient.connect();
因此,该代码为我提供状态ok,并在活动中传递正确的天气数据

代码为ACL\u访问被拒绝。 位置已启用,已获得权限

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

有人有办法吗

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

public class SenderService extends IntentService {
private GoogleApiClient mGoogleApiClient;
private void handleActionWeather() {
    mGoogleApiClient  = new GoogleApiClient.Builder(getApplicationContext(), new GoogleApiClient.ConnectionCallbacks() {
        @Override
        public void onConnected(@Nullable Bundle bundle) {
            Log.w("a", "wsconn");              handleActionWeatherSupport(mGoogleApiClient);
        }
        @Override
        public void onConnectionSuspended(int i) {
        }
    }, new GoogleApiClient.OnConnectionFailedListener() {
        @Override
        public void onConnectionFailed(@NonNull ConnectionResult connectionResult) {
            Log.w("a", "wsconnfail:" + connectionResult.toString());
        }
    }).addApi(Wearable.API).addApi(Awareness.API).useDefaultAccount().build();
    mGoogleApiClient.connect();
}
private void handleActionWeatherSupport(final GoogleApiClient mGoogleApiClient) {
    if (ActivityCompat.checkSelfPermission(getApplication(), android.Manifest.permission.ACCESS_FINE_LOCATION) != PackageManager.PERMISSION_GRANTED) {
        return;
    }
    Awareness.SnapshotApi.getWeather(mGoogleApiClient).setResultCallback(new ResultCallback<WeatherResult>() {
            @Override
            public void onResult(@NonNull WeatherResult wr) {
                if (!wr.getStatus().isSuccess()) {
                    Log.w("a", wr.getStatus().toString());
                    return;
                }
                Weather we = wr.getWeather();
                Log.w("a", "got:" + we.toString());
            }
        });
}
...
公共类SenderService扩展了IntentService{
私人GoogleapClient MGoogleapClient;
私人空间handleActionWeather(){
mgoogleapclient=new GoogleapClient.Builder(getApplicationContext(),new GoogleapClient.ConnectionCallbacks()){
@凌驾
未连接的公共无效(@Nullable Bundle){
Log.w(“a”、“wsconn”);handleActionWeatherSupport(MGoogleapClient);
}
@凌驾
公共空间连接暂停(int i){
}
},新的GoogleAppClient.OnConnectionFailedListener(){
@凌驾
public void onconnection失败(@NonNull ConnectionResult ConnectionResult){
Log.w(“a”,“wsconnfail:+connectionResult.toString());
}
}).addApi(Wearable.API).addApi(Awareness.API).useDefaultAccount().build();
mGoogleApiClient.connect();
}
私有void handleActionWeatherSupport(最终GoogleAppClient MgoogleAppClient){
if(ActivityCompat.checkSelfPermission(getApplication(),android.Manifest.permission.ACCESS\u FINE\u LOCATION)!=PackageManager.permission\u已授予){
返回;
}
Awareness.SnapshotApi.getWeather(mGoogleApiClient.setResultCallback(new-ResultCallback()){
@凌驾
公共void onResult(@NonNull WeatherResult wr){
如果(!wr.getStatus().issucess()){
Log.w(“a”,wr.getStatus().toString());
返回;
}
Weather we=wr.getWeather();
Log.w(“a”,“get:+we.toString());
}
});
}
...

}

IntentService在哪里?正如我所写的,这是相似的,但复制到那里。您是否尝试过使用
Service
,而不是
IntentService
?它也不起作用。我知道您说过位置已启用,但GPS已启用(“位置设置中的高精度”或“仅限设备”)?
public class SenderService extends IntentService {
private GoogleApiClient mGoogleApiClient;
private void handleActionWeather() {
    mGoogleApiClient  = new GoogleApiClient.Builder(getApplicationContext(), new GoogleApiClient.ConnectionCallbacks() {
        @Override
        public void onConnected(@Nullable Bundle bundle) {
            Log.w("a", "wsconn");              handleActionWeatherSupport(mGoogleApiClient);
        }
        @Override
        public void onConnectionSuspended(int i) {
        }
    }, new GoogleApiClient.OnConnectionFailedListener() {
        @Override
        public void onConnectionFailed(@NonNull ConnectionResult connectionResult) {
            Log.w("a", "wsconnfail:" + connectionResult.toString());
        }
    }).addApi(Wearable.API).addApi(Awareness.API).useDefaultAccount().build();
    mGoogleApiClient.connect();
}
private void handleActionWeatherSupport(final GoogleApiClient mGoogleApiClient) {
    if (ActivityCompat.checkSelfPermission(getApplication(), android.Manifest.permission.ACCESS_FINE_LOCATION) != PackageManager.PERMISSION_GRANTED) {
        return;
    }
    Awareness.SnapshotApi.getWeather(mGoogleApiClient).setResultCallback(new ResultCallback<WeatherResult>() {
            @Override
            public void onResult(@NonNull WeatherResult wr) {
                if (!wr.getStatus().isSuccess()) {
                    Log.w("a", wr.getStatus().toString());
                    return;
                }
                Weather we = wr.getWeather();
                Log.w("a", "got:" + we.toString());
            }
        });
}
...