开发者

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.

Basically i would like 开发者_Python百科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.

ContentObserver.onChange is going to be called every time something changes in Gmail. 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); 
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜