I want to read Gmail mails in my own android app. Is there anyway to do it using android sdk? If not, what are the other options? parsing gmail atom?
I ask and answer that question here. You need Gmail.java code (in the question there are a link) and you must understand that you shouldn't use that undocumented provider
Are there any good short code examples that simply read a new gmail message?
It's possible using the GMail API, here are some steps I found helpful.
Be sure to add at least the read-only scope for proper permissions. In the sample the scopes are defined in an array:
private static final String[] SCOPES = { GmailScopes.GMAIL_LABELS, mailScopes.GMAIL_READONLY };
My intention was to read all subjects. I used the following code (which is the adapted getDataFromApi method from the official sample):
private List<String> getDataFromApi() throws IOException {
// Get the labels in the user's account. "me" referes to the authentized user.
String user = "me";
List<String> labels = new ArrayList<String>();
ListMessagesResponse response = mService.users().messages().list(user).execute();
for (Message message : response.getMessages()) {
Message readableMessage = mService.users().messages().get(user, message.getId()).execute();
if (readableMessage.getPayload() != null) {
for (MessagePartHeader header : readableMessage.getPayload().getHeaders()) {
if (header.getName().compareToIgnoreCase("Subject") == 0) {
labels.add(header.getValue());
}
}
}
}
return labels;
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With