public class MainActivity extends Activity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
}
public void send(View v){
//拿到用户输入的号码和内容
EditText et_phone = (EditText) findViewById(R.id.et_phone);
EditText et_content = (EditText) findViewById(R.id.et_content);
String phone = et_phone.getText().toString();
String content = et_content.getText().toString();
//1.获取短信管理器
SmsManager sm = SmsManager.getDefault();
//2.切割短信,把长短信分成若干个小短信
ArrayList<String> smss = sm.divideMessage(content);
//3.for循环把集合中所有短信全部发出去
for (String string : smss) {
sm.sendTextMessage(phone, null, string, null, null);
}
}
}
发送短信代码 注意加权限
最新推荐文章于 2024-01-17 11:57:17 发布