访问通过谷歌Android帐户名/用户名 [英] Accessing Google Account Id /username via Android
问题描述
如何访问用户的谷歌帐户名/用户名在code?我建立,将调用的web服务来存储数据的应用程序,并欲识别提交数据的人的身份。
How do you access the user's Google Account Id / username in code? I am building an application that will call a web service to store data and I want to identify the identity of the person submitting the data.
推荐答案
我遇到同样的问题,解决了我的这两个环节:
I've ran into the same issue and these two links solved for me:
第一个是这一个:<一href="http://stackoverflow.com/questions/4038333/how-do-i-retrieve-the-logged-in-google-account-on-android-phones">How重新获取登录谷歌帐户Android手机?
其中presents的code检索与手机相关联的账户。基本上你将需要的东西是这样的:
Which presents the code for retrieving the accounts associated with the phone. Basically you will need something like this:
AccountManager manager = (AccountManager) getSystemService(ACCOUNT_SERVICE);
Account[] list = manager.getAccounts();
和添加权限在AndroidManifest.xml
And to add the permissions in the AndroidManifest.xml
<uses-permission android:name="android.permission.GET_ACCOUNTS"></uses-permission>
<uses-permission android:name="android.permission.AUTHENTICATE_ACCOUNTS"></uses-permission>
此外,如果您使用的是仿真器下面的链接将帮助您设置了一个帐户:<一href="http://stackoverflow.com/questions/3260868/android-emulator-trouble-creating-user-accounts">Android模拟器 - 麻烦创建用户帐户
Additionally, if you are using the Emulator the following link will help you to set it up with an account : Android Emulator - Trouble creating user accounts
基本上,它说,根据一个API级别,而不是SDK版本(像通常一样),你必须创建一个Android设备。
Basically, it says that you must create an android device based on a API Level and not the SDK Version (like is usually done).
这篇关于访问通过谷歌Android帐户名/用户名的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!