Android的 - 通过内置的SMS应用
问题描述:
排在首位,我使用模拟器来测试这个发送短信。 我要开的消息(发送作为参数)的文本的默认短信应用程序,并允许用户采取从那里控制(和内置应用程序)。 我用这个代码:Android的 - 通过内置的SMS应用
Button btnSMS = (Button) findViewById(R.id.btnSMS);
btnSMS.setOnClickListener(new View.OnClickListener() {
public void onClick(View arg0) {
Intent it = new Intent(Intent.ACTION_VIEW);
it.putExtra("sms_body", "text");
it.setType("vnd.android-dir/mms-sms");
}
});
当我按下按钮没有任何反应。我希望SMS默认应用程序打开,与文本等各个领域,用户必须填写,然后发送邮件。这是因为模拟器还是我的代码?我还指定清单中的权限:
<使用许可权的android:NAME = “android.permission.SEND_SMS”/ >
答
你缺少startActivity ::
Intent it = new Intent(Intent.ACTION_VIEW);
it.putExtra("sms_body", "text");
it.setType("vnd.android-dir/mms-sms");
startActivity(it);
或您可以使用下面的代码也::
String number = "12346556"; // The number on which you want to send SMS
startActivity(new Intent(Intent.ACTION_VIEW, Uri.fromParts("sms", number, null)));
答
发送短信与内置的短信应用程序:
Intent i = new Intent(android.content.Intent.ACTION_VIEW);
i.putExtra("address", "09090909; 092322424; 123456778");
i.putExtra("sms_body", "SMS Content");
i.setType("vnd.android-dir/mms-sms");
startActivity(i);
什么乱七八糟的在我的头上!谢谢! – ali 2012-04-23 14:06:25
感谢这段代码工作完美.... !!!!! – 2014-01-22 06:40:06