在android上打开主要的SMS会话意图

时间:2013-05-27 06:51:08

标签: android android-intent sms mms

如何从我自己的活动中启动android mms / sms主要会话意图?我发现的最佳答案是:

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

我认为它在其中一个设备上运行此代码时甚至有效,但现在我收到以下错误:

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

注意: 我不打开sms / mms编辑器屏幕来发送短信,但是主sms屏幕存储了所有到达的sms / mms消息。

3 个答案:

答案 0 :(得分:3)

在Galaxy S3和S4中,我们应该使用intent.setClassName(“com.android.mms”,“com.android.mms.ui.ConversationComposer”);

答案 1 :(得分:3)

在Fresher的帮助下,我得到了它的工作,这是我使用的代码:

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

答案 2 :(得分:0)

在清单文件中添加这些权限

    <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" />

希望这有帮助