MikeL
MikeL

Reputation: 5611

Opening the main SMS conversation intent on android

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.

Upvotes: 5

Views: 4070

Answers (3)

TouchBoarder
TouchBoarder

Reputation: 6492

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

Upvotes: 3

Fresher
Fresher

Reputation: 279

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

Upvotes: 3

bakriOnFire
bakriOnFire

Reputation: 2681

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

Upvotes: 0

Related Questions