从多个活动访问谷歌加客户端 [英] Access google plus client from multiple activities

查看:121
本文介绍了从多个活动访问谷歌加客户端的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我开发我在其中集成了谷歌加的应用程序。到目前为止,它工作正常,我能够检索用户配置文件。

I'm developing an application in which i have integrated google plus. So far Its working fine, I am able to retrieve the user profile.

但现在我要做到以下几点:

But now i want to do the following:

1)我有两个活动 signInActivity shareActivity

1)I have two activity signInActivity and shareActivity.

2)如果用户使用的是已签到 signInActivity 那么它不应该要求再次签到 shareActivity ,应直接共享的内容。

2)If user is already signin using signInActivity then it should not ask for signin again in shareActivity and should directly share the content.

3)如果用户没有signedin在 signInActivity 并尝试使用共享数据 shareActivity 那么应用程序应签到用户,然后只共享数据。在这种情况下,如果用户可以追溯到 signInActivity 那么应用程序应显示您已经signedin

3)If user is not signedin in the signInActivity and try to share data using shareActivitythen app should signin the user and then only share the data. In this case if user goes back to the signInActivity then app should show that "you have already signedin"

总之我想用户的登入是中央内的应用程序,这样如果alrady signedin应该从任何活动进行访问。

In short i want user signin to be Central within application so that if it is alrady signedin it should be accessible from any activity.

我听说过的访问令牌,但我不知道如何使用它,文件说,它过期一小时,这是不是我想要的。

I have heard about the access token but i dont know how to use it and document says that it expires in an hour which is not what i want.

我怎样才能让中央谷歌加的登入?可能吗?或者我需要在每一个活动的用户进行身份验证?

How can i make central google plus signin? is it possible? or i need to authenticate user in each activity?

推荐答案

在每个活动管理GoogleApiClient的一个单独的实例会的不可以结果在用户被要求在多次登录。

Managing a separate instance of GoogleApiClient in each activity will not result in the user being asked to sign in multiple times.

Google+登录功能(即GoogleApiClient)提供了一个接口的谷歌帐户的设备上和谷歌播放服务,核心服务 - 它不按GoogleApiClient比如有状态。因此,一旦设备帐户已被认证为你的应用程序,GoogleApiClient的新实例将访问相同的状态。 GoogleApiClient是专门设计成为一个轻量级的方式来访问谷歌Play业务管理的中央国家。

Google+ Sign-in (ie. GoogleApiClient) provides an interface to the Google accounts on the device and the Google Play services core service - it doesn't have state per GoogleApiClient instance. So once a device account has been authenticated for your app, new instances of GoogleApiClient will access the same state. GoogleApiClient is specifically designed to be a lightweight way to access the central state managed by Google Play services.

您很幸运,关于​​访问令牌!谷歌Play业务负责所有令牌管理的为您服务。因此,尽管访问令牌只持续一小时,就像你说的,如果你尝试用你的PlusClient访问谷歌API和您的访问令牌已经过期,谷歌Play业务将透明的要求为您新的访问令牌并完成呼叫。

You're in luck regarding access tokens! Google Play services takes care of all token management for you. So although access tokens only last for one hour, as you say, if you try to use your PlusClient to access a Google API and your access token has expired, Google Play services will transparently request a new access token for you and complete the call.

看看这个谷歌I / O聊的更多详细信息,第一部分:

Take a look at the first part of this Google I/O talk for more details:

http://www.youtube.com/watch?v=_KBHf1EODuk

这篇关于从多个活动访问谷歌加客户端的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆