2017-06-09 62 views
0

我試着去定義它基於從方法自定義「更新谷歌播放服務」對話框

googleApiAvailability.isGooglePlayServicesAvailable(活動)未來的狀態碼顯示錯誤對話框;

此方法返回然後得到傳遞給方法

googleApiAvailability.getErrorDialog(活動,狀態2404).show()的狀態碼;

然後向用戶顯示一個對話框,詢問他們是否需要更新Google Play服務或根據錯誤代碼(本例中爲「狀態」)啓用它們等。從我可以告訴他們是基於狀態設置對話框文本,但我想定製它有點,因爲我用它來通知,所以我想在對話框中說,用戶將無法使用通知沒有這個功能安裝/啓用/更新的應用程序?

此外,我想能夠添加一個取消按鈕與自定義文本,如「它是好的」或沿着這些行?

我在另一個應用中看到類似的東西,並認爲這是一個好主意。

編輯:

public static boolean checkGooglePlayServices(Activity activity) { 
    GoogleApiAvailability googleApiAvailability = GoogleApiAvailability.getInstance(); 
    int status = googleApiAvailability.isGooglePlayServicesAvailable(activity); 
    if (status != ConnectionResult.SUCCESS) { 
     if (googleApiAvailability.isUserResolvableError(status)) { 
     Dialog dialog = googleApiAvailability.getErrorDialog(activity, status, 1); 
     dialog.setTitle("This is a test title"); 
     dialog.show(); 
     } 
     return false; 
    } 
    return true; 
    } 
+1

我認爲最簡單的方法是建立自己的對話框。或者,如果你的解決方案非常糟糕,getErrorDialog()返回一個對話框,你可以在顯示它之前操作它的View ... – lelloman

+0

@lelloman我已經試過了,看起來我不能改變對話框中的文本,只有真正奇怪的標題 – x10sion

+0

也許你想添加你試過的問題的代碼,如果改變對話框的文本將是一個很好的解決方案,也許我們可以使它工作。無論如何,這是骯髒的,只需要自己的對話,它只需要很少的努力 – lelloman

回答

0

resultCode爲可以具有低於值。

public static final int SUCCESS = 0; 
public static final int SERVICE_MISSING = 1; 
public static final int SERVICE_VERSION_UPDATE_REQUIRED = 2; 
public static final int SERVICE_DISABLED = 3; 
public static final int SIGN_IN_REQUIRED = 4; 
public static final int INVALID_ACCOUNT = 5; 
public static final int RESOLUTION_REQUIRED = 6; 
public static final int NETWORK_ERROR = 7; 
public static final int INTERNAL_ERROR = 8; 
public static final int SERVICE_INVALID = 9; 
public static final int DEVELOPER_ERROR = 10; 
public static final int LICENSE_CHECK_FAILED = 11; 
public static final int CANCELED = 13; 
public static final int TIMEOUT = 14; 
public static final int INTERRUPTED = 15; 
public static final int API_UNAVAILABLE = 16; 
public static final int SIGN_IN_FAILED = 17; 
public static final int SERVICE_UPDATING = 18; 
public static final int SERVICE_MISSING_PERMISSION = 19; 
public static final int RESTRICTED_PROFILE = 20; 

不叫getErrorDialog而不是打電話給你owndialog,並採取相應的行動..

static String getStatusString(int var0) { 
     switch(var0) { 
     case -1: 
      return "UNKNOWN"; 
     case 0: 
      return "SUCCESS"; 
     case 1: 
      return "SERVICE_MISSING"; 
     case 2: 
      return "SERVICE_VERSION_UPDATE_REQUIRED"; 
     case 3: 
      return "SERVICE_DISABLED"; 
     case 4: 
      return "SIGN_IN_REQUIRED"; 
     case 5: 
      return "INVALID_ACCOUNT"; 
     case 6: 
      return "RESOLUTION_REQUIRED"; 
     case 7: 
      return "NETWORK_ERROR"; 
     case 8: 
      return "INTERNAL_ERROR"; 
     case 9: 
      return "SERVICE_INVALID"; 
     case 10: 
      return "DEVELOPER_ERROR"; 
     case 11: 
      return "LICENSE_CHECK_FAILED"; 
     case 13: 
      return "CANCELED"; 
     case 14: 
      return "TIMEOUT"; 
     case 15: 
      return "INTERRUPTED"; 
     case 16: 
      return "API_UNAVAILABLE"; 
     case 17: 
      return "SIGN_IN_FAILED"; 
     case 18: 
      return "SERVICE_UPDATING"; 
     case 19: 
      return "SERVICE_MISSING_PERMISSION"; 
     case 20: 
      return "RESTRICTED_PROFILE"; 
     case 21: 
      return "API_VERSION_UPDATE_REQUIRED"; 
     case 42: 
      return "UPDATE_ANDROID_WEAR"; 
     case 99: 
      return "UNFINISHED"; 
     case 1500: 
      return "DRIVE_EXTERNAL_STORAGE_REQUIRED"; 
     default: 
      return (new StringBuilder(31)).append("UNKNOWN_ERROR_CODE(").append(var0).append(")").toString(); 
     } 
    } 

PS:見ConnectionResult.java類的更多信息。

+0

我已經考慮過這個以及我沒有真正看過的問題是處理每個場景(可以修復由用戶)喜歡啓用的服務,更新(直接到谷歌播放商店)或該服務一般缺少 – x10sion