Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/unity3d/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Android 是否可以询问用户是否想要更新google play服务?_Android_Google Cloud Messaging - Fatal编程技术网

Android 是否可以询问用户是否想要更新google play服务?

Android 是否可以询问用户是否想要更新google play服务?,android,google-cloud-messaging,Android,Google Cloud Messaging,在google play服务的示例中,他们处理可能的版本更新,如下所示: int resultCode = GooglePlayServicesUtil.isGooglePlayServicesAvailable(from); if (resultCode != ConnectionResult.SUCCESS) { if (GooglePlayServicesUtil.isUserRecoverableError(resultCode)) {

在google play服务的示例中,他们处理可能的版本更新,如下所示:

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");
            }
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();

}
这会产生一条类似以下内容的消息

“如果你不更新谷歌服务,你的应用程序将无法运行”

对于我的应用程序来说,这句话太强了,因为我只使用这些服务来提供一些操作功能

我可以用我自己的对话框替换Google PlayServiceSutil.getErrorDialog()对话框吗

理想的情况下,我想要像

“需要谷歌服务更新。是/否”


你可以这样做:

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");
            }
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();

}

好的,您不必显示“播放服务错误”对话框,但是如果您显示自己的,您就可以自己引导用户通过播放商店更新播放服务。我不知道是否有正式的文档记录。我目前没有显示更新对话框,没有。但是,这样用户就不知道他可以更新并获得更多功能。我认为Google Play对话框消息有点误导,我的应用程序没有停止工作,他们怎么知道它会停止工作?“我的应用程序没有停止工作,他们怎么知道它会停止工作?”——它们基于您编译的Play Services SDK。您的清单中有一个
元素(手动添加或可能通过清单合并)提供您正在使用的SDK的信息。这反过来又会驱动所需的最低播放服务安装,如果设备正在运行较旧的安装(或完全缺少播放服务),这反过来会驱动错误对话框。您不能只检查结果以及它是否为
ConnectionResult。服务版本更新需要
,询问用户是否要更新。如果是,请致电GooglePlayServicesUtil.getErrorDialog(结果…)。“我不更新是否遗漏了任何潜在的危险?”--只要用户没有更新,您实际上没有使用播放服务,就没有风险。@Alex打算直接重定向到google播放服务,请参见以下问题: