Android 检查google play服务
谷歌文档中经常忽略文档的重要性,这让我抓狂。如果我不是秃头的话,我早就把头发拔了Android 检查google play服务,android,google-cloud-messaging,Android,Google Cloud Messaging,谷歌文档中经常忽略文档的重要性,这让我抓狂。如果我不是秃头的话,我早就把头发拔了 private void checkGooglePlayServices() { int errorCode = GoogleApiAvailability.getInstance().isGooglePlayServicesAvailable(this); boolean isErrorResolvable = GoogleApiAvailability.getInstance().isUserResol
private void checkGooglePlayServices() {
int errorCode = GoogleApiAvailability.getInstance().isGooglePlayServicesAvailable(this);
boolean isErrorResolvable = GoogleApiAvailability.getInstance().isUserResolvableError(errorCode);
if (isErrorResolvable) {
GoogleApiAvailability.getInstance().getErrorDialog(this, errorCode, REQUEST_CODE_GOOGLE_PLAY_SERVICES).show();
} else {
if (errorCode == ConnectionResult.SUCCESS) {
launchApplication();
}
}
}
上面的代码显示了一个对话框,上面有一个按钮,上面写着“获取google play服务”:
@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
super.onActivityResult(requestCode, resultCode, data);
if (requestCode == REQUEST_CODE_GOOGLE_PLAY_SERVICES) {
}
}
现在我该怎么办?我应该如何引导用户到play store以获取play服务的更新?我认为
getErrorResolutionPendingContent
在这里很有用,但我不知道该怎么做
请帮助我。您可以使用此代码在App Store上打开Google Play服务页面:
try {
startActivity(new Intent(Intent.ACTION_VIEW, Uri.parse("market://details?id=" + GoogleApiAvailability.GOOGLE_PLAY_SERVICES_PACKAGE)));
} catch (android.content.ActivityNotFoundException anfe) {
startActivity(new Intent(Intent.ACTION_VIEW, Uri.parse("https://play.google.com/store/apps/details?id=" + GoogleApiAvailability.GOOGLE_PLAY_SERVICES_PACKAGE)));
}
您可以使用以下代码在App Store上打开Google Play服务页面:
try {
startActivity(new Intent(Intent.ACTION_VIEW, Uri.parse("market://details?id=" + GoogleApiAvailability.GOOGLE_PLAY_SERVICES_PACKAGE)));
} catch (android.content.ActivityNotFoundException anfe) {
startActivity(new Intent(Intent.ACTION_VIEW, Uri.parse("https://play.google.com/store/apps/details?id=" + GoogleApiAvailability.GOOGLE_PLAY_SERVICES_PACKAGE)));
}
您可以使用以下内容查看Google Play服务:
if (checkPlayServices()) {
// Do your calculation here.
}
private boolean checkPlayServices() {
GoogleApiAvailability apiAvailability = GoogleApiAvailability.getInstance();
int resultCode = apiAvailability.isGooglePlayServicesAvailable(this);
if (resultCode != ConnectionResult.SUCCESS) {
if (apiAvailability.isUserResolvableError(resultCode)) {
apiAvailability.getErrorDialog(this, resultCode, PLAY_SERVICES_RESOLUTION_REQUEST)
.show();
} else {
Log.i(TAG, "This device is not supported.");
finish();
}
return false;
}
return true;
}
这将帮助您检查Google Play服务。您可以使用以下内容检查Google Play服务:
if (checkPlayServices()) {
// Do your calculation here.
}
private boolean checkPlayServices() {
GoogleApiAvailability apiAvailability = GoogleApiAvailability.getInstance();
int resultCode = apiAvailability.isGooglePlayServicesAvailable(this);
if (resultCode != ConnectionResult.SUCCESS) {
if (apiAvailability.isUserResolvableError(resultCode)) {
apiAvailability.getErrorDialog(this, resultCode, PLAY_SERVICES_RESOLUTION_REQUEST)
.show();
} else {
Log.i(TAG, "This device is not supported.");
finish();
}
return false;
}
return true;
}
这将帮助您查看Google Play服务。谢谢。接受答案,如果有用的话。这并不能解决我的问题。我也实现了你上面的建议。我不知道如何打开playstore到google play服务的相关页面。现在,当我按下“获取谷歌播放服务”时,它只会调用我的OnActivityResultThank。接受答案,如果有用的话。这并不能解决我的问题。我也实现了你上面的建议。我不知道如何打开playstore到google play服务的相关页面。现在,当我按下“获取谷歌播放服务”时,它只会调用我的OnActivityResultThank。这就是困扰我的地方。谢谢。这就是困扰我的地方。