我想与我的Android应用程序使用谷歌云消息传递。据说你需要先检查谷歌播放服务的可用性。但我不知道如何实现这一点。刚刚通过GoogleApiAvailability Class搜索过。问题是我不明白如何设置检查和使用方法.getErrorDialog()在我的情况下。据说requestCode是“调用startActivityForResult时给出的requestCode”。但是如何使用呢?
public void onResume() {
GoogleApiAvailability availability = GoogleApiAvailability.getInstance();
int checkForGPS = availability.isGooglePlayServicesAvailable(this);
if(checkForGPS != ConnectionResult.SUCCESS) {
availability.getErrorDialog(this, checkForGPS, requestCode);
}
super.onResume();
}
答案 0 :(得分:0)
试试这个,
private boolean checkPlayServices() {
int resultCode = GooglePlayServicesUtil.isGooglePlayServicesAvailable(this);
if (resultCode != ConnectionResult.SUCCESS) {
if (GooglePlayServicesUtil.isUserRecoverableError(resultCode)) {
GooglePlayServicesUtil.getErrorDialog(resultCode, this, PLAY_SERVICES_RESOLUTION_REQUEST).show();
} else {
Log.e(TAG, "This device is not supported.");
finish();
}
return false;
}
return true;
}