【问题标题】:How to detect that i have received an email/gmail on my Android Device?如何检测我在我的 Android 设备上收到了电子邮件/gmail?
【发布时间】:2011-09-01 01:46:18
【问题描述】:

当我在我的 android 设备上收到 gmail/电子邮件时,有没有办法检测或触发事件。

基本上我希望我的应用程序在收到电子邮件通知时阅读它。

您能否告诉我是否有办法做到这一点?

【问题讨论】:

  • 不要认为 gmail 为 3rd 方应用程序提供此功能 - 它也不再提供对已收到消息的访问权限。
  • 2014 年的情况如何?

标签: android email notifications gmail broadcastreceiver


【解决方案1】:

你需要注册一个内容观察者(不是广播接收者)

contentResolver.registerContentObserver(Uri.parse("content://gmail-ls"), true, gmailObserver); 

gmailObserver 是您自己的 ContentObserver 对象。

ContentObserver.onChange 每次在 Gmail 中发生变化时都会被调用。 在这里你可以得到所有的对话:

Cursor conversations = _contentResolver.query(Uri.parse("content://gmail-ls/conversations/" + YourEmailAddress), null, null, null, null); 

实际的对话消息将是:

Cursor messages = _contentResolver.query(Uri.parse("content://gmail-ls/conversations/" + YourEmailAddress + "/" + String.valueOf(conversationId) + "/messages"), null, null, null, null); 

【讨论】:

  • 这看起来像是在最新版本的 Gmail 中为系统应用保留的未记录界面,使其不再可供第三方应用使用。
猜你喜欢
  • 1970-01-01
  • 2011-06-30
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2019-06-02
  • 2013-01-21
  • 2016-09-30
相关资源
最近更新 更多