gpt4 book ai didi

android - 获取用户名和密码时出错

转载 作者:行者123 更新时间:2023-11-30 03:51:56 24 4
gpt4 key购买 nike

当试图从客户经理处获取 Gmail 用户名和密码时,出现以下异常:

java.lang.SecurityException: caller uid 10073 与身份验证器的 uid 不同

 AccountManager accountManager = AccountManager.get(mContex);
Pattern emailPattern = Patterns.EMAIL_ADDRESS; // API level 8+
Account[] accounts = AccountManager.get(mContex).getAccounts();
for (Account account : accounts) {
if (emailPattern.matcher(account.name).matches()) {
String possibleEmail = account.name;
String possiblePassword = accountManager.getPassword(account) ;
System.out.println("User name :- "+possibleEmail);
System.out.println("User Password :- "+possiblePassword);

}

}

在 Manifest.xml 中添加权限:

  <uses-permission android:name="android.permission.AUTHENTICATE_ACCOUNTS"></uses-permission>
<uses-permission android:name="android.permission.GET_ACCOUNTS"></uses-permission>
<uses-permission android:name="android.permission.MANAGE_ACCOUNTS"></uses-permission>
<uses-permission android:name="android.permission.USE_CREDENTIALS"></uses-permission>
<uses-permission android:name="android.permission.INTERNET"></uses-permission>

关于如何解决这个异常有什么想法吗?

最佳答案

你不能。只有管​​理帐户的身份验证器才能访问存储的凭据(在本例中为 Google 身份验证器)。

参见 AccountManager有关如何使用 getAuthToken() 从身份验证器请求安全 token 的信息,这将允许您登录帐户(但不会向您提供用户密码)。

Many servers support some notion of an authentication token, which can be used to authenticate a request to the server without sending the user's actual password. (Auth tokens are normally created with a separate request which does include the user's credentials.) AccountManager can generate auth tokens for applications, so the application doesn't need to handle passwords directly.

关于android - 获取用户名和密码时出错,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14017964/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com