launch sms application with an intent

2019-01-01 03:45发布

I have a question about an intent... I try to launch the sms app...

Intent intent = new Intent(Intent.ACTION_MAIN);
intent.setType("vnd.android-dir/mms-sms");
int flags = Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_SINGLE_TOP |
    Intent.FLAG_ACTIVITY_CLEAR_TOP;
intent.setFlags(flags);
intent.setData(Uri.parse("content://sms/inbox"));
context.startActivity(intent);

so, you can see that I put too much things in my intent, but that's because I don't know how I can do... Thank's

18条回答
倾城一夜雪
2楼-- · 2019-01-01 04:08
Intent intent = new Intent(Intent.ACTION_MAIN);
intent.addCategory(Intent.CATEGORY_DEFAULT);
intent.setType("vnd.android-dir/mms-sms");
startActivity(intent);

That's all you need.

查看更多
孤独寂梦人
3楼-- · 2019-01-01 04:10

Here is the code that will open the SMS activity pre-populated with the phone number to which the SMS has to be sent. This works fine on emulator as well as the device.

Intent smsIntent = new Intent(Intent.ACTION_SENDTO);
smsIntent.addCategory(Intent.CATEGORY_DEFAULT);
smsIntent.setType("vnd.android-dir/mms-sms");
smsIntent.setData(Uri.parse("sms:" + phoneNumber); 
查看更多
泛滥B
4楼-- · 2019-01-01 04:10

Compose SMS :

Uri smsUri = Uri.parse("tel:" + to);
Intent intent = new Intent(Intent.ACTION_VIEW, smsUri);
intent.putExtra("address", to);
intent.putExtra("sms_body", message);
intent.setType("vnd.android-dir/mms-sms");
startActivity(intent);
查看更多
步步皆殇っ
5楼-- · 2019-01-01 04:16
try {
    Intent smsIntent = new Intent(Intent.ACTION_VIEW);
    smsIntent.setData(Uri.parse("smsto:" + Uri.encode(number)));
    smsIntent.putExtra("address", number);
    smsIntent.putExtra("sms_body", message);

    PackageManager pm = activity.getPackageManager();
    List<ResolveInfo> resInfo = pm.queryIntentActivities(smsIntent, 0);

    for (int i = 0; i < resInfo.size(); i++) {
        ResolveInfo ri = resInfo.get(i);
        String packageName = ri.activityInfo.packageName;

        if (packageName.contains("sms")) {
            //Log.d("TAG", packageName + " : " + ri.activityInfo.name);
            smsIntent.setComponent(new ComponentName(packageName, ri.activityInfo.name));
        }
    }
    activity.startActivity(smsIntent);
} catch (Exception e) {
    // Handle Error
}

Best way of doing this.

查看更多
春风洒进眼中
6楼-- · 2019-01-01 04:18

To start launch the sms activity all you need is this:

Intent sendIntent = new Intent(Intent.ACTION_VIEW);         
sendIntent.setData(Uri.parse("sms:"));

You can add extras to populate your own message and such like this

sendIntent.putExtra("sms_body", x); 

then just startActivity with the intent.

startActivity(sendIntent);
查看更多
笑指拈花
7楼-- · 2019-01-01 04:19

The best code that works with Default SMS app is.

Uri SMS_URI = Uri.parse("smsto:+92324502****"); //Replace the phone number
Intent sms = new Intent(Intent.ACTION_VIEW,SMS_URI);    
sms.putExtra("sms_body","This is test message"); //Replace the message witha a vairable 
startActivity(sms);
查看更多
登录 后发表回答