2016-05-09 164 views
0

它讓我瘋狂在谷歌文檔中經常忽略的重要文檔。如果我不是禿頭的話,我會拔掉我的頭髮。檢查谷歌播放服務

private void checkGooglePlayServices() { 
    int errorCode = GoogleApiAvailability.getInstance().isGooglePlayServicesAvailable(this); 
    boolean isErrorResolvable = GoogleApiAvailability.getInstance().isUserResolvableError(errorCode); 

    if (isErrorResolvable) { 
    GoogleApiAvailability.getInstance().getErrorDialog(this, errorCode, REQUEST_CODE_GOOGLE_PLAY_SERVICES).show(); 
    } else { 
    if (errorCode == ConnectionResult.SUCCESS) { 
     launchApplication(); 
    } 
    } 
} 

上面的代碼顯示一個對話框,說有一個按鈕閱讀獲取谷歌播放服務

@Override 
protected void onActivityResult(int requestCode, int resultCode, Intent data) { 
    super.onActivityResult(requestCode, resultCode, data); 
    if (requestCode == REQUEST_CODE_GOOGLE_PLAY_SERVICES) { 

    } 
} 

現在我該怎麼辦嗎?我應該如何引導用戶到Play商店獲取遊戲服務的更新?我認爲 getErrorResolutionPendingIntent在這裏有用,但我不知道如何去做這件事。

請幫助我。

回答

2

您可以使用此代碼來打開谷歌Play業務頁上的應用程序商店:

try { 
    startActivity(new Intent(Intent.ACTION_VIEW, Uri.parse("market://details?id=" + GoogleApiAvailability.GOOGLE_PLAY_SERVICES_PACKAGE))); 
} catch (android.content.ActivityNotFoundException anfe) { 
    startActivity(new Intent(Intent.ACTION_VIEW, Uri.parse("https://play.google.com/store/apps/details?id=" + GoogleApiAvailability.GOOGLE_PLAY_SERVICES_PACKAGE))); 
} 
+0

謝謝。這讓我很困擾。 –

3

您可以查看谷歌Play業務與此:

if (checkPlayServices()) { 
    // Do your calculation here. 
} 

private boolean checkPlayServices() { 
    GoogleApiAvailability apiAvailability = GoogleApiAvailability.getInstance(); 
    int resultCode = apiAvailability.isGooglePlayServicesAvailable(this); 
    if (resultCode != ConnectionResult.SUCCESS) { 
     if (apiAvailability.isUserResolvableError(resultCode)) { 
      apiAvailability.getErrorDialog(this, resultCode, PLAY_SERVICES_RESOLUTION_REQUEST) 
        .show(); 
     } else { 
      Log.i(TAG, "This device is not supported."); 
      finish(); 
     } 
     return false; 
    } 
    return true; 
} 

這將幫助你檢查谷歌播放服務。

+0

謝謝。接受答案,如果有用的話。 – Dhruv

+0

這不能解決我的問題。我也已經達到了你上面提出的建議。我不知道如何打開Playstore到谷歌播放服務的相關頁面。現在當我按「獲取谷歌播放服務」,它只是調用我的onactivity結果 –