Android 如何连接多个Google Play服务API';它与castapi一起使用
我正在使用google+登录的google play服务,因此我需要它在应用程序启动时连接,但Cast API要求在我可以连接到google play服务之前选择一个Android 如何连接多个Google Play服务API';它与castapi一起使用,android,google-play-services,chromecast,Android,Google Play Services,Chromecast,我正在使用google+登录的google play服务,因此我需要它在应用程序启动时连接,但Cast API要求在我可以连接到google play服务之前选择一个CastDevice,但当应用程序启动时,这是不可能的 这就是我目前的设置方式 @Override protected void onCreate(Bundle savedInstanceState) { .... mGoogleApiClient = new GoogleApiClient.Builder(this
CastDevice
,但当应用程序启动时,这是不可能的
这就是我目前的设置方式
@Override
protected void onCreate(Bundle savedInstanceState) {
....
mGoogleApiClient = new GoogleApiClient.Builder(this)
.addConnectionCallbacks(this)
.addOnConnectionFailedListener(this)
.addApi(Plus.API)
.addApi(Drive.API)
.addApi(Cast.API,apiOptionsBuilder.build()) //not possible to be ready yet at this point
.addScope(Plus.SCOPE_PLUS_LOGIN)
.addScope(Drive.SCOPE_FILE)
.build();
....
}
如果用户需要选择cast设备,我无法在此处连接,但需要在活动开始进行身份验证时连接
那么,当您还需要其他API时,如何处理使用Cast API呢?我需要有两个GoogleAppClient实例吗?我也面临同样的问题。我最初创建一个没有强制转换的Google客户端,当我需要开始强制转换时,我断开连接并创建一个新的客户端。我怀疑这是最好的解决办法,但到目前为止似乎是可行的。如果您找到了更好的方法,请与他人分享。如果您需要更早地连接其他API,您可以使用不同的实例。