简体   繁体   English

如何检测到我在Android设备上收到了电子邮件/ gmail?

[英]How to detect that i have received an email/gmail on my Android Device?

Is there a way to detect or an event being triggered when i receive a gmail/email on my android device. 当我在Android设备上收到gmail /电子邮件时,有没有一种方法可以检测到事件或触发事件。

Basically i would like my application to read the email notification when i receive it. 基本上,我希望我的应用程序在收到电子邮件通知时阅读它。

Could you kindly tell me if there is way to do this ? 您能否告诉我是否有办法做到这一点?

You need to register a content observer (not broadcast receiver) 您需要注册一个内容观察者(不是广播接收者)

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

gmailObserver is your own ContentObserver object. gmailObserver是您自己的ContentObserver对象。

ContentObserver.onChange is going to be called every time something changes in Gmail. ContentObserver.onChange Gmail中发生任何更改时,都会调用ContentObserver.onChange Here you get all conversations like so: 在这里,您可以像这样进行所有对话:

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

And the actual conversation messages will be: 实际的对话消息将是:

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何检测 email 客户端是否配置在 Android 设备上? - How do I detect if an email client is configured on an Android device? Android-我的活动如何检测到我在Firebase Messaging Service中收到了通知? - Android - How can my Activity detect that I received a notification in Firebase Messaging Service? 我怎么知道从Android设备上安装的所有应用发送或接收的数据是什么? - how can i know what data is being sent or received from all the apps installed on my android device? 如何检测设备是否为Android Wear? - How can I detect if device is an android wear? 如何检测 Android 设备没有内置电池? - How to detect that Android device doesn't have built-in battery? 如何检测我的android设备是否支持android中的otg电缆 - How to detect whether my android device supports otg cable in android Gmail Android版在我的电子邮件布局中增加了空白 - Gmail for android adds a gap in my email layout 当我插入手机时,android studio 没有检测到设备 - android studio detect no device when i plug my phone 如果我有 id 或 threadId,我可以在 Gmail 应用程序中打开我的电子邮件线程吗? - Can I open my email thread in Gmail App If I have id or threadId? 如何从应用程序内部通过电子邮件发送android设备的日志文件? - How can I send the log file of the android device via email from inside my app?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM