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

痞子三分冷 提交于 2019-12-22 01:30:53

问题


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 my application to read the email notification when i receive it.

Could you kindly tell me if there is way to do this ?


回答1:


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); 


来源:https://stackoverflow.com/questions/7265351/how-to-detect-that-i-have-received-an-email-gmail-on-my-android-device

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