5

How can I launch an android mms/sms main conversation intent from my own activity? The best answer I found till now was:

Intent intent = new Intent(Intent.ACTION_MAIN);
intent.addCategory(Intent.CATEGORY_LAUNCHER);
intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
intent.setClassName("com.android.mms", "com.android.mms.ui.ConversationList");
context.startActivity(intent);

And I think it even worked when I run this code on one of the devices, but now I get the following error:

Permission Denial: starting Intent { act=android.intent.action.MAIN cat=[android.intent.category.LAUNCHER] flg=0x10000000 cmp=com.android.mms/.ui.ConversationList } from ProcessRecord{460a37f8 6949:msc.test/10081} (pid=6949, uid=10081) requires null

Note: I am not interested in opening the sms/mms composer screen to send the sms, but the main sms screen where all the arrived sms/mms messages are stored.

MikeL
  • 5,385
  • 42
  • 41

3 Answers3

3

In Galaxy S3 and S4, we should use intent.setClassName("com.android.mms", "com.android.mms.ui.ConversationComposer");

Fresher
  • 269
  • 5
  • 16
3

With help from Fresher answer I got it working, here is the code I use:

private boolean tryOpenSMSConversation(){
        boolean isWorking = false;
        Intent intent = new Intent(Intent.ACTION_MAIN);
        // DEFAULT ANDROID DEVICES
        intent.setComponent(new ComponentName("com.android.mms",
                "com.android.mms.ui.ConversationList"));
        isWorking = tryActivityIntent(this, intent);
        if (!isWorking) {
            // SAMSUNG DEVICES S3|S4|NOTE 2 etc.
            intent.setComponent(new ComponentName("com.android.mms",
                    "com.android.mms.ui.ConversationComposer"));
            isWorking = tryActivityIntent(this, intent);
        }
        if (!isWorking) {
            // OPENS A NEW CREATE MESSAGE 
            intent = new Intent(Intent.ACTION_MAIN);
            intent.setType("vnd.android-dir/mms-sms");
            isWorking = tryActivityIntent(this, intent);
        }
        if (!isWorking) {
            // TODO try something else
        }
        return isWorking;
    }

    public static boolean tryActivityIntent(Context context,
            Intent activityIntent) {

        // Verify that the intent will resolve to an activity
        try {
            if (activityIntent.resolveActivity(context.getPackageManager()) != null) {
                context.startActivity(activityIntent);
                return true;
            }
        }  catch (SecurityException e) {
            return false;
        }
        return false;
    }
TouchBoarder
  • 6,422
  • 2
  • 52
  • 60
0

Add these permissions in the manifest file

    <uses-permission android:name="android.permission.READ_CONTACTS" />
    <uses-permission android:name="android.permission.READ_PHONE_STATE" />
    <uses-permission android:name="android.permission.SEND_SMS" />
    <uses-permission android:name="android.permission.RECEIVE_SMS" />
    <uses-permission android:name="android.permission.READ_SMS" />
    <uses-permission android:name="android.permission.WRITE_SMS" />
    <uses-permission android:name="android.permission.RECEIVE_MMS" />

Hope this helps

bakriOnFire
  • 2,685
  • 1
  • 15
  • 27
  • I don't think that you should add all those permissions just to open the main MMS/SMS conversation intent. Nevertheless I added the missing ones to my manifest file and still get the error Permission Denial. Maybe it is because some devices can not access the com.android.mms.ui.ConversationList? – MikeL May 28 '13 at 06:11