[英]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.