Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to open a particular message/conversation in the Gmail app

Tags:

android

I am trying to programmatically open an individual email in the Gmail app on Android.

I know it can be done because the built-in notifications send you to a message when you click on them and there's an app on the market called Gmail Notifier which does it as well.

What I've tried so far:

-send an ACTION_VIEW intent with the message URI as data (failed - cannot resolve URI)

-send an intent to open HtmlConversationActivity in the Gmail package (failed - "requires permission: null")

Would it help to add flags or a category to the intent? If so, which one(s)?

I know that the Gmail app is not well-documented, but it drives me mad that there is definitely a way to do it and I just can't figure it out!

P.S.: This is the first time I'm posting on stackoverflow, so I apologise in advance if I have ignored any conventions.

like image 777
katzoft Avatar asked Aug 28 '10 22:08

katzoft


2 Answers

It might be possible, but google has made sure it will be impossible. I spent a couple of hours trying to make it work:

  1. Pulled the Gmail.apk from my rooted phone.
  2. Decompiled it using apktools.
  3. Went over the manifest.xml

2 Activities seem to be useful for it:

activity android:theme="@android:style/Theme.Light.NoTitleBar" 
         android:label="@string/activity_conversation" 
         android:name="HtmlConversationActivity" 
         android:configChanges="keyboardHidden|orientation"

and

activity android:label="@string/activity_search" android:name="SearchActivity" 

Both of them have no intent filters so you can't call them. If you try you will get

Permission Denial: starting Intent { act=android.intent.action.VIEW flg=0x10000000 cmp=com.google.android.gm/.HtmlConversationActivity } from ProcessRecord{40b7d248 26043:co.il.gmailresearch/10154} (pid=26043, uid=10154) requires null

It might be possible using the com.google.android.gm.ConversationListActivity. But the code must be obfuscated and I didn't bother to get the source code of the Gmail.apk to verify which flags they use...

EDIT: Well OK I did bother to check it, and surprising enough Google did not obfuscate their Gmail app :) So I was able to get the source code of the APK. Did some digging and this is what I found...

The relevant Activity is ConverstaionListActivity.

In the Manifest.xml it has this intent filter:

action android:name="android.intent.action.SEARCH"/>

As i inspected the code for the activity I found out that there are 3 expected string to get as extra:

public static final String EXTRA_LABEL = "label";
public static final String EXTRA_SEARCH = "search";
public static final String EXTRA_TITLE = "title";

Anyways. button line, you can't open a specific conversation. but you can pass a search query that will display only your specific conversation from all the mails the user has.

Intent mailClient = new Intent(Intent.ACTION_SEARCH);
mailClient.setClassName("com.google.android.gm", "com.google.android.gm.ConversationListActivity");
mailClient.putExtra("query", "15 Apps for Programming");                
startActivity(mailClient);
like image 169
ZiviMagic Avatar answered Sep 27 '22 20:09

ZiviMagic


I am trying to programmatically open an individual email in the Gmail app on Android.

There are no documented and supported Intents for working with the Gmail application. Developers are not supposed to be tightly integrating with this application -- if Google wanted such integration, they would document and support such integration, as they have done with contacts.

like image 30
CommonsWare Avatar answered Sep 27 '22 19:09

CommonsWare