2016-11-18 62 views
0

我想创建一个通用函数来检查谷歌播放服务是否可用。当我创建一个通用功能时,我不使用getErrorDialog,因为它需要参考Activity如何使用getErrorResolutionPendingIntent来检查谷歌播放服务

我已经看到了几个更多的选项,如getErrorResolutionPendingIntent,但我不知道如何使用它。

这里是代码

public static boolean isGooglePlayServiceAvailable(Activity activity){ 

     GoogleApiAvailability googleService = GoogleApiAvailability.getInstance(); 

     int result = googleService.isGooglePlayServicesAvailable(getContext()); 
     if(result != ConnectionResult.SUCCESS){ 
      if(googleService.isUserResolvableError(result)){ 

       PendingIntent pendingResults = googleService.getErrorResolutionPendingIntent(getContext(), new ConnectionResult(result));    


      }else{ 

       Log.e(TAG , "Device not supported"); 
      } 
      return false; 
     } 

     return true; 

    } 

回答

0

PendingIntent.send将执行与此相关的意图的任何行动。同样来自文档

如果hasResolution()为true,那么将返回getResolution()。 否则,如果Google Play服务过期或缺失,则返回的PendingIntent会将用户定向到Play商店 ,如果设备上禁用了Google Play服务,则系统设置为 。

+1

如何使用它,如果我想在上面的代码中实现它 – Hunt