朋友我正在制作一个安全应用程序,当用户点击忘记密码并且我想将他的密码发送到与Google Play帐户相关联的G-mail帐户时.所以问题是,我怎么才能知道他的G-mail ID?
您可以使用AccountManager.getAccounts或AccountManager.getAccountsByType获取设备上所有帐户名的列表.
Pattern emailPattern = Patterns.EMAIL_ADDRESS; // API level 8+
Account[] accounts = AccountManager.get(context).getAccounts();
for (Account account : accounts) {
if (emailPattern.matcher(account.name).matches()) {
String possibleEmail = account.name;
...
}
}
Run Code Online (Sandbox Code Playgroud)
需要GET_ACCOUNTS权限:
uses-permission android:name ="android.permission.GET_ACCOUNTS"/>
您也可以使用https://developers.google.com/gmail/android/上的代码
| 归档时间: |
|
| 查看次数: |
1188 次 |
| 最近记录: |