Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
336 views
in Technique[技术] by (71.8m points)

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

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.

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

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

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...