4

这是我用来调用 SMS 应用程序的一段代码:

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

在 os 版本低于 Android 3.0 的设备上,上述代码运行正常,SMS 页面被打开并且要发送的消息和数字被正确预填,但在 Android 3.0 及更高版本的设备中,这不再工作了。

在 Android 3.0 中调用 SMS Intent 并填充数字而不是文本,而在 Android 4.0 中调用 SMS Intent 并填充文本而不是数字。

有谁知道这个问题的解决方案?

4

2 回答 2

1

此代码适用于所有版本的 android

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);
于 2012-05-19T10:40:18.727 回答
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..."

但在新代码中,我将文本和数字分开。

于 2012-05-21T13:14:44.090 回答