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

流过昼夜 提交于 2019-12-04 20:27:23
Alex Davis

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); 
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!