Android 3.0及以上版本中SMS应用意向不起作用

4

这是我用来调用短信应用的代码:

Intent intent = new Intent(Intent.ACTION_SENDTO, Uri.parse(uri));
            intent.putExtra("sms_body", body);
            intent.putExtra("compose_mode", true);
            launchIntent(intent);

在Android 3.0以下的设备上,上述代码可以正常工作,短信页面会被打开,并且待发送的短信和号码都能够正确地预填。但在Android 3.0及以上版本的设备上,这个方法就无法再起作用了。
在Android 3.0中,短信意图被调用时只会填充号码而不是文本;而在Android 4.0中,短信意图被调用时只会填充文本而不是号码。
有谁知道这个问题的解决方法吗?
2个回答

1

这段代码适用于所有版本的安卓系统。

String smsBody = Resources.getString("InvitationBody", getBaseContext()) + Local.User.FirstName;
Intent sendIntent = new Intent(Intent.ACTION_VIEW);
sendIntent.putExtra("sms_body", smsBody); 
sendIntent.setType("vnd.android-dir/mms-sms");
startActivity(sendIntent);

Intent sendIntent = new Intent(Intent.ACTION_VIEW, Uri.parse(uri)); 我像上面这样使用,现在消息已经填好了,但发送者的号码缺失了... - Siva K

0

以下代码完美运行

                String body = "This is the message i need to send";
                String num  = "smsto:999416231";
                String[] tokens = num.split(":");
                Intent sendIntent = new Intent(Intent.ACTION_VIEW);
                sendIntent.putExtra("address",tokens[1]);
                sendIntent.putExtra("sms_body", body); 
                sendIntent.setType("vnd.android-dir/mms-sms");
                startActivity(sendIntent);  

我在问题中提到的代码用于将数字作为Uri.parse(uri)传递,其值为"smsto:9941..."

但在新代码中,我正在拆分文本和数字。


以上代码的问题在于它强制用户使用Android股票短信应用程序,因为您设置了意图的“类型”值。 - Camille Sévigny

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接