Android4.4无法使用“vnd.android-dir / mms-sms”处理sms意图

问题描述 投票:13回答:3

我的应用程序有一个按钮来启动默认短信活动,它工作得很好所有Android版本,除了新的,Android 4.4(kitkat)这是代码:

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

我收到错误消息

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

我知道谷歌对默认的短信应用如何处理短信意图做了一些改变。但我的应用程序不是短信应用程序,但它只具有启动默认短信应用程序与收件人号码的功能。所以请帮忙。

java android android-intent sms android-4.4-kitkat
3个回答
28
投票

要使用数字填充的使用操作ACTION_SENDTO启动SMS应用程序:

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

这适用于Android 4.4。它也适用于早期版本的Android,但由于API从未公开,因此行为可能会有所不同。如果您没有使用先前方法的问题,我可能会坚持4.4之前的版本并使用ACTION_SENDTO 4.4+。


0
投票

要启动短信应用程序而不插入数字,您应该删除setType

Intent intent = new Intent(Intent.ACTION_VIEW);
intent.setData(Uri.parse("sms:"));
intent.putExtra("sms_body", "smsMsgVar");
startActivity(intent);

0
投票

当您使用Emulator进行测试时,问题就出现了,

请用实际设备测试。

© www.soinside.com 2019 - 2024. All rights reserved.