Created
March 9, 2020 15:28
-
-
Save oradkovsky/915f0071ed1897423742de8d2aa61015 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// You may have guessed this is body of suspend function as I'm using Kotlin coroutines. | |
// Service is com.google.api.services.gmail.Gmail. | |
try { | |
val executeResult: ListMessagesResponse? = | |
withContext(Dispatchers.IO) { | |
service.users().messages()?.list("me")?.setQ("to:me")?.execute() | |
} | |
// For the sake of test, let's get 1st message on the list | |
val message: Message? = executeResult?.messages?.get(0) | |
// Actual reading of the message, by message ID | |
val messageRead = withContext(Dispatchers.IO) { | |
service.users().messages() | |
?.get(FirebaseAuth.getInstance().currentUser?.email, message?.id) | |
?.setFormat("full")?.execute() | |
} | |
// At this point you can get to short version of your message body as messageRead?.snippet | |
} catch (e: UserRecoverableAuthIOException) { | |
startActivityForResult(e.intent, RQ_GMAIL_ACCESS); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment