获取Android手机的主要电子邮件帐户 [英] get Primary Email Account of android phone

查看:233
本文介绍了获取Android手机的主要电子邮件帐户的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在处理一个项目,并且必须自动填充EditText和用户的主电子邮件,我正在考虑将主电子邮件作为与Google Play商店关联的电子邮件。我已阅读帖子并实施,

如果我们使用AccountManager类来创建电子邮件ID,我们将获得该手机中添加的所有电子邮件ID,所以这是不可能的,有些人说接收由AccountManager返回的第一个电子邮件ID,但返回第一次添加到手机中的电子邮件ID。




假设我已添加test@gmail.com并将其与Google Play相关联,后来我添加了test_new@gmail.com并将此帐户与Play商店相关联,现在我正在使用该帐户的Play商店。如果我写了如下代码;

 帐户[] accountList = AccountManager.get(this).getAccountsByType(com.google); 
Log.d(Play store account:,accountList [0] .name);

声明的预期结果是 test_new@gmail.com ,但我得到了test@gmail.com



有什么办法可以解决这个问题吗?

请帮忙我推荐你的想法。

解决方案

据我所知,android中没有主电子邮件ID的概念。并且无法获取与Play商店关联的电子邮件ID。所以我做的是,我已经获取了所有的gmail ID并拿到了最后一个,它不是主要的电子邮件ID,但它应该是他的设备中第一个添加的Google帐户。所以在正常使用情况下,用户不会玩他第一次添加的电子邮件ID。因此我们可以将其视为主要邮件ID。


I am working on a project, and I have to fill the EditText automatically with the user's primary email, I am considering primary email as the email that associated with google play store. I have read this post and implemented that,

if we are using the AccountManager class for geting the email ids, we will get all the email id added in that phone, so that is not possible, and some says to take the first email id that returned by the AccountManager, but that returns the email id that added in the phone for the first time.

ie, suppose I have added test@gmail.com and linked that with google play, later I have added test_new@gmail.com and associated this account with play store, right now I am using play store with this account. if I have wrote code as follows ;

        Account[] accountList = AccountManager.get(this).getAccountsByType("com.google");
    Log.d("Play store account:" , accountList[0].name);

the expected out put for the statement is test_new@gmail.com, but I am getting test@gmail.com

is there any way to solve this issue ?

please help me contributing your ideas.

解决方案

As far as I read, there is no concept of primary email id in android. and there is no way to get e-mail id associated with play store. so what I did is, I have fetched all gmail ids and took the last one, it is not the main email id, but it should be the first added google account in his device. so in normal use cases user won't play with his first added email id. so we can assume it as primary mail id.

这篇关于获取Android手机的主要电子邮件帐户的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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