在他们为谷歌播放服务提供的示例中,他们处理可能的版本更新,如下所示:
int resultCode = GooglePlayServicesUtil.isGooglePlayServicesAvailable(from);
if (resultCode != ConnectionResult.SUCCESS) {
if (GooglePlayServicesUtil.isUserRecoverableError(resultCode)) {
GooglePlayServicesUtil.getErrorDialog(resultCode, context,
PLAY_SERVICES_RESOLUTION_REQUEST).show();
} else {
error(TAG, "this device is not supported");
}
这会产生类似
的消息"如果您不更新Google服务,您的应用程序将无法运行。
对于我的应用程序,此声明太强大,因为我只使用这些服务来提供一些可选功能。
我可以用某个方式替换GooglePlayServicesUtil.getErrorDialog()
对话框吗?
理想情况下,我想要像
这样的东西" Google服务更新是可取的。是/否"
答案 0 :(得分:7)
int resultCode = GooglePlayServicesUtil.isGooglePlayServicesAvailable(from);
if (resultCode != ConnectionResult.SUCCESS) {
// show your own AlertDialog for example:
AlertDialog.Builder builder = new AlertDialog.Builder(getActivity());
// set the message
builder.setMessage("This app use google play services only for optional features")
.setTitle("Do you want to update?"); // set a title
builder.setPositiveButton(R.string.ok, new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int id) {
// User clicked OK button
final String appPackageName = "com.google.android.gms";
try {
startActivity(new Intent(Intent.ACTION_VIEW, Uri.parse("market://details?id=" + appPackageName)));
}catch (android.content.ActivityNotFoundException anfe) {
startActivity(new Intent(Intent.ACTION_VIEW, Uri.parse("https://play.google.com/store/apps/details?id=" + appPackageName)));
}
}
});
builder.setNegativeButton(R.string.cancel, new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int id) {
// User cancelled the dialog
}
});
AlertDialog dialog = builder.create();
}