安卓用户ID帐户(而不是ID电话) [英] Android: user ID account (not ID phone)

查看:224
本文介绍了安卓用户ID帐户(而不是ID电话)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个应用程序,节省了用户的形象,但我会每幅图像也保存用户ID。

I have an app that save the user image but i would save with each image also user id.

用户可以更改电话设备,但谷歌帐户是始终不变的。

The user can change telephone device but the google account is always the same.

我需要识别用户,而不是手机code字符串。

I need a code string that identify the user and not the phone.

也许一个数字ID,不一定Google帐户的电子邮件。

Maybe a numeric id, not necessarily google account email.

我有这样的code,但错误的是(返程设备ID,而不是用户ID)

I have this code but is wrong (return device id and not user id)

TelephonyManager tm = (TelephonyManager) getSystemService(TELEPHONY_SERVICE);
telephoneCode = tm.getDeviceId();

String code=Settings.Secure.getString(getContentResolver(), Settings.Secure.ANDROID_ID);

## ## ## ##

我有测试

AccountManager mgr = AccountManager.get(getApplicationContext());
Account[] accounts = mgr.getAccountsByType("com.google");
String userCode=accounts.toString();

在此code返回一个字符串:

In this code return a string:

[Landroid.accounts.Account;@318ca48b

这个字母code随时更改!

This alphanumeric code always change!

感谢的
丹尼尔。

Thank's Daniele.

推荐答案

下面是我如何做到这一点:

Here is how I do it:

AccountManager accountManager = AccountManager.get(getApplicationContext());

Account[] accounts = accountManager.getAccountsByType("com.google");

for (Account a: accounts) {
    if (a.name.contains("@gmail.com")) {
        return a.name;
    }
}

这将返回在@ gmail.com结尾的第一个帐户;可以有一个以上的

This will return the first account that ends in @gmail.com; there can be more than one.

这篇关于安卓用户ID帐户(而不是ID电话)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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