呼叫需要用户可能拒绝的权限:Awareness.SnapshotApi.getWeather()

时间:2017-10-20 06:33:05

标签: android google-awareness

尝试从googeleAwareness api.Error获取天气更新说:调用需要用户可能拒绝的权限:代码应明确检查权限是否可用(使用checkPermission)或显式处理潜在的{{ 1}}。这是我的代码:

SecurityException

}

我的manifest.xml文件的权限:

public class MainActivity extends AppCompatActivity {

private static final String TAG = "Awareness";
private GoogleApiClient mGoogleApiClient;
private TextView tv;

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);

    mGoogleApiClient = new GoogleApiClient.Builder(MainActivity.this)
            .addApi(Awareness.API)
            .build();
    mGoogleApiClient.connect();
    initSnapshots();
}

private void initSnapshots() {
    Awareness.SnapshotApi.getWeather(mGoogleApiClient)
            .setResultCallback(new ResultCallback<WeatherResult>() {
                @Override
                public void onResult(@NonNull WeatherResult weatherResult) {
                    if (!weatherResult.getStatus().isSuccess()) {
                        tv.setText("weather failed");
                        return;
                    }
                    Weather weather = weatherResult.getWeather();
                    tv.setText(weather + "");
                }
            });
}

0 个答案:

没有答案