我想问你: 1-如何在不将用户移至“消息”框的情况下通过我的应用程序发送短信 我只想让用户插入文本,然后他/她点击发送按钮 之后直接将短信发送到我在代码中写的特定号码?
我使用了如下所示的代码,它运行良好,但它让我转到了消息框:( 有什么建议吗?
MyButton.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
// TODO Auto-generated method stub
String str= MyEditText.getText().toString();
// For SMS
Uri smsUri = Uri.parse("I wrote my number here");
Intent intent = new Intent(Intent.ACTION_VIEW, smsUri);
intent.putExtra("sms_body", "Besm Allah");
intent.setType("vnd.android-dir/mms-sms"); startActivity(intent);
}
});
======================更新后======================= =========
最佳答案
您正在使用一个 Intent 对象 (new Intent(Intent.ACTION_VIEW ...),它会调用内置的 SMS 应用程序来帮助您发送 SMS 消息。因此您将被重定向到消息框。
为了在不被定向到消息框的情况下完成发送消息过程,您需要使用 PendingIntent
。看看这个很棒的 SMS 教程,它很可能会解决您的问题。 http://mobiforge.com/developing/story/sms-messaging-android
关于java - 通过 Android 应用程序发送短信而不移动到消息框默认应用程序,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9569121/