Google 云消息传递:如何使用 GoogleApiAvailability Class 请求 google 播放服务可用性
Google Cloud Messaging: how to ask for google play services availability with GoogleApiAvailability Class
我想为我的 android 应用程序使用 google 云消息传递。据说您需要先检查 google 播放服务的可用性。但我不知道如何实施。刚刚通过 GoogleApiAvailability Class 进行了搜索。问题是我不明白如何在我的案例中设置检查和使用方法 .getErrorDialog() 。据说requestCode是"The requestCode given when calling startActivityForResult"。但是如何使用呢?
public void onResume() {
GoogleApiAvailability availability = GoogleApiAvailability.getInstance();
int checkForGPS = availability.isGooglePlayServicesAvailable(this);
if(checkForGPS != ConnectionResult.SUCCESS) {
availability.getErrorDialog(this, checkForGPS, requestCode);
}
super.onResume();
}
试试这个,
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;
}
我想为我的 android 应用程序使用 google 云消息传递。据说您需要先检查 google 播放服务的可用性。但我不知道如何实施。刚刚通过 GoogleApiAvailability Class 进行了搜索。问题是我不明白如何在我的案例中设置检查和使用方法 .getErrorDialog() 。据说requestCode是"The requestCode given when calling startActivityForResult"。但是如何使用呢?
public void onResume() {
GoogleApiAvailability availability = GoogleApiAvailability.getInstance();
int checkForGPS = availability.isGooglePlayServicesAvailable(this);
if(checkForGPS != ConnectionResult.SUCCESS) {
availability.getErrorDialog(this, checkForGPS, requestCode);
}
super.onResume();
}
试试这个,
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;
}