Android应用程序开发:如何获取Google Gmail帐户凭据以自动发送电子邮件?

发布于 2025-01-05 11:52:49 字数 733 浏览 0 评论 0原文

我正在尝试创建一个使用 Gmail 帐户自动发送电子邮件的应用程序。

如果用户已经在 Android 设备中添加了 Gmail 帐户,我不希望用户输入用户名和密码,但我希望应用程序使用该帐户自动发送电子邮件。

我已经知道如何获取用户名和密码,但是当我询问密码时,出现以下错误:

02-14 10:53:40.660: E/AndroidRuntime(23719): Caused by: java.lang.SecurityException: caller uid xxxxx is different than the authenticator's uid

其中 xxxxx 是 UID 号。 我的代码是这样的:

 AccountManager manager = AccountManager.get(this);
 Account[] accounts = manager.getAccountsByType("com.google");
 for (Account account : accounts){
   if(account.name.endsWith("gmail.com")){
      String gmailAddress = account.name;
      String password = manager.getPassword(account);
   }
 }

请给我一个示例代码或阅读它的链接。不要给我任何其他东西。 许多他克斯

I'm trying to create an application that uses a Gmail account to send emails automatically.

I do not want that the user enters username and password if he has already added a Gmail account in his Android Device, but I want the application uses that account to send email automatically.

I already know how to get the username and password but when I ask for the password I get the following error:

02-14 10:53:40.660: E/AndroidRuntime(23719): Caused by: java.lang.SecurityException: caller uid xxxxx is different than the authenticator's uid

Where xxxxx is the UID number.
My code is this:

 AccountManager manager = AccountManager.get(this);
 Account[] accounts = manager.getAccountsByType("com.google");
 for (Account account : accounts){
   if(account.name.endsWith("gmail.com")){
      String gmailAddress = account.name;
      String password = manager.getPassword(account);
   }
 }

Please give my an example code or a link to read it. Don't give me anything else.
Many Thaks

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

暖心男生 2025-01-12 11:52:49

仅当您共享相同的 UID 时,才可以获取谷歌帐户凭据,而当您编写自己的应用程序时,这是不可能的。我认为您需要使用用户在手机中注册帐户时生成的 AuthToken。您可以与访问令牌以便自动发送邮件..

getting google account credentials is possible only when You share same UID which is not possible when you are writing you are own application.I think You need to use AuthToken that is generated ehen Ever user registers account in the phone.You can exchange Auth token with acesss token in order to send mail automatically..

独守阴晴ぅ圆缺 2025-01-12 11:52:49

包含权限

<uses-permission android:name="android.permission.GET_ACCOUNTS" />

您应该在 AndroidManifest.xml

You should include

<uses-permission android:name="android.permission.GET_ACCOUNTS" />

permission to your AndroidManifest.xml

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文