2015-06-20 56 views
3

在他们对谷歌播放服务的例子,他们处理可能出现的版本更新如下:是否可以询问用户是否要更新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"); 
      } 

这将导致一个消息像

“如果你不您的应用程序将无法正常工作” t更新Google服务“。

对我的应用程序来说,这个声明太强大了,因为我只使用服务来提供一些操作功能。

我可以采用某种替代GooglePlayServicesUtil.getErrorDialog()对话框,我自己一个人?

理想情况下,我想有这样的事情

“谷歌服务的更新是可取的是/否”。

+0

AFAIK你不必显示“播放服务”错误对话框,但如果您显示自己的内容,则可以通过Play商店以某种方式引导用户更新播放服务。我不知道这是否正式记录。 – CommonsWare

+0

我目前没有显示更新对话框,没有。但是,这样用户不知道他可以更新并获得更多功能。我认为Google Play对话消息有点让人误解,我的应用不停止工作,他们怎么知道它的确如此? –

+1

“我的应用不停止工作,他们怎么知道它呢?” - 它们基于您正在编译的Play Services SDK。您的清单中有一个''元素(手动添加或可能通过清单合并)提供您正在使用的SDK的相关信息。这反过来又驱动了最低要求的播放服务安装,如果该设备正在摇摆较旧的安装(或完全缺乏播放服务),则该安装反过来驱动错误对话框。 – CommonsWare

回答

6

你可以做这样的事情:

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

} 
+0

是的,正如@marco表示将会有2个对话框 –

+1

@Alex直接使用意图重定向到谷歌播放服务,看到这个问题:http://stackoverflow.com/questions/27032717/how-to-open-google- play-store-app-directly-without-chooser-intent –

+0

@Alex我编辑了我的答案,看一看。 –

相关问题