2016-05-09 162 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结果 –