这似乎是一个简单的事情,如果他们想使用谷歌加号与他们的应用程序大部分人将需要:秒。访问GoogleApiClient对象
在活动1:
我登录的用户
中,我想使该用户对象全局可访问的符号后,所以我把它添加到应用程序对象:
public class GlobalUserAccess extends Application {
private GoogleApiClient mGoogleApiClient;
public GlobalUserAccess(){
mGoogleApiClient = null;
}
public void setClient(GoogleApiClient client){
mGoogleApiClient = client;
}
public GoogleApiClient getClient(){
return mGoogleApiClient;
}
}
通过绑定它像这样:
GlobalUserAccess client = ((GlobalUserAccess) getApplicationContext());
client.setClient(mGoogleApiClient);
然而,当我尝试访问它在活动2:
GlobalUserAccess client = ((GlobalUserAccess) getApplicationContext());
String currentUser = Plus.AccountApi.getAccountName(client.getClient());
我得到的错误:
E/GMPM: getGoogleAppId failed with status: 10
可有人请填写我在用正确的方法来做到这一点?我希望将该用户对象提供给所有类,并且我在这方面花费了太多时间:|。
难道我弄乱的地方?啊......
编辑:客户创建自Activity 1码
mGoogleApiClient = new GoogleApiClient.Builder(this)
.addConnectionCallbacks(this)
.addOnConnectionFailedListener(this)
.addApi(Plus.API)
.addScope(new Scope(Scopes.PROFILE))
.addScope(new Scope(Scopes.EMAIL))
.build();
我直接使用Google的代码从他们的Git仓库。它成功地签署并获取活动1.
你如何创建mGoogleApiClient发布其代码。 – Sabeeh
完成!我编辑了我的帖子。 – Kris