Android4.4 can not handle sms intent with “vnd.and

2019-01-17 16:46发布

My application has a button to start default sms activity and it worked perfectly fine all android version except new one, Android 4.4(kitkat) Here is the code:

public void onClick(View arg0) {
    Intent smsIntent = new Intent(Intent.ACTION_VIEW);
    smsIntent.setType("vnd.android-dir/mms-sms");
    smsIntent.putExtra("address", member.getPhoneNumber().trim());
    context.startActivity(smsIntent);
}

And I get error messages

11-08 02:08:32.815: E/AndroidRuntime(14733): android.content.ActivityNotFoundException: No Activity found to handle Intent { act=android.intent.action.VIEW typ=vnd.android-dir/mms-sms (has extras) }

I know that google made some changes on how the default sms app handles sms intents. but my app is not a sms app but it only has function to start default sms app with recipient number. so please help.

1条回答
Melony?
2楼-- · 2019-01-17 17:46

To start the SMS app with number populated use action ACTION_SENDTO:

Intent intent = new Intent(Intent.ACTION_SENDTO);
intent.setData(Uri.parse("smsto:" + Uri.encode(phoneNumber)));
startActivity(intent);

This will work on Android 4.4. It should also work on earlier versions of Android however as the APIs were never public the behavior might vary. If you didn't have issues with your prior method I would probably just stick to that pre-4.4 and use ACTION_SENDTO for 4.4+.

查看更多
登录 后发表回答