Android的按钮点击自动发送短信 [英] Android send SMS automatically on button click

查看:851
本文介绍了Android的按钮点击自动发送短信的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想自动发送短信到一定数量时,用户presses屏幕上的按钮。

I am trying to automatically send SMS message to a certain number when the user presses a button on the screen.

这是我的code:

Intent smsIntent = new Intent(Intent.ACTION_SENDTO,
Uri.parse("sms:xxxxxxxxxxx")); 
smsIntent.putExtra("sms_body", "Hello");
startActivity(smsIntent);

XXXXXXX =电话号码

xxxxxxx = phone number

我有以下权限:

<uses-permission android:name="android.permission.SEND_SMS"></uses-permission>
<uses-permission android:name="android.permission.RECEIVE_SMS"></uses-permission>

当我preSS的按钮,它带我到另一个屏幕,在这里我可以编辑我的文字和preSS发送。我只是希望它自动执行此操作过程中没有带我到另一个屏幕。正如我已经定义我的消息,我只是想将它发送到特定号码。

When I press the button it takes me to another screen where I can edit my text and press Send. I just want it to do this process automatically without taking me to another screen. As I've already defined my message, I just want to send it to a particular number.

和也,我不知道如果我把corrent电话号码在code中的第二行。我必须把我的祖国code。在那里第一次或者我只是把我的手机号码,这是否行得通呢?

And also I am not sure if I put the corrent phone number in the second line of code. Do I have to put my country code in there first or can I just put my mobile phone number and it will work?

感谢您

推荐答案

试试这个code:

 String messageToSend = "this is a message";
 String number = "2121234567";

 SmsManager.getDefault().sendTextMessage(number, null, messageToSend, null,null);

至于多少,你需要输入,如果你是从电话的呼叫,或发送短信按正常方式的数量。

With regards to the number, you need to enter the number as if you were calling it from the phone or sending an sms message in the normal manner.

这篇关于Android的按钮点击自动发送短信的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆