2015-06-20 53 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我編輯了我的答案,看一看。 –

相關問題