public class MainActivity extends Activity implements OnClickListener {
private EditText et_number;
private EditText et_content;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
et_number = (EditText) findViewById(R.id.et_number);
et_content = (EditText) findViewById(R.id.et_content);
Button bt_send = (Button) findViewById(R.id.bt_send);
bt_send.setOnClickListener(this);
}
@Override
public void onClick(View v) {
switch (v.getId()) {
case R.id.bt_send:
String content = et_content.getText().toString().trim();
String number = et_number.getText().toString().trim();
if(TextUtils.isEmpty(content)||TextUtils.isEmpty(number)) {
Toast.makeText(this, "电话号码或者内容不能为空!", Toast.LENGTH_LONG).show();
return ;
} else {
SmsManager smsManager = SmsManager.getDefault();
ArrayList<String> contents = smsManager.divideMessage(content);
for(String str : contents) {
smsManager.sendTextMessage(number, null, str, null, null);
}
}
break;
default:
break;
}
}
}