Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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.

like image 526
MikeL Avatar asked May 27 '13 06:05

MikeL


People also ask

How do I open SMS app on Android?

Open Settings . Click Apps. In the list of apps, click Messages. SMS.

How do I send a message with intent?

Built-in SMS applicationIntent sendIntent = new Intent(Intent. ACTION_VIEW); sendIntent. putExtra("sms_body", "default content"); sendIntent. setType("vnd.


2 Answers

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

like image 124
Fresher Avatar answered Oct 11 '22 03:10

Fresher


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;
    }
like image 28
TouchBoarder Avatar answered Oct 11 '22 03:10

TouchBoarder