public class MainActivity extends Activity {
private Button btn;
private EditText phoneEt,contextEt;
private OnClickListener btnListener = new OnClickListener() {
@SuppressWarnings("deprecation")
@Override
public void onClick(View arg0) {
// TODO Auto-generated method stub
String phoneNumber = phoneEt.getText().toString();
String context = contextEt.getText().toString();
SmsManager manager = SmsManager.getDefault(); //获得默认的消息管理器
ArrayList<String> list = manager.divideMessage(context); //拆分长短信
for (String text : list) {
manager.sendTextMessage(phoneNumber, null, text, null, null); //发送短信
}
Toast.makeText(getApplicationContext(), "发送完毕", Toast.LENGTH_SHORT).show();
}
};
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
btn = (Button)this.findViewById(R.id.button1);
phoneEt = (EditText)this.findViewById(R.id.editText1);
contextEt = (EditText)this.findViewById(R.id.editText2);
btn.setOnClickListener(btnListener);
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.main, menu);
return true;
}
}
android应用集成短信
最新推荐文章于 2021-05-28 21:37:42 发布