视频完毕,参照教程,仿做了个发送短信的
同样需要启动两个模拟器测试
===========================
===========================
部分代码:
/**
* <p>
* 短信发送器<br/>
* 2012-02-01
* </p>
* @author bo
*
*/
public class SmsActivity extends Activity {
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
Button button = (Button)this.findViewById(R.id.button);
//通过匿名内部类实现监听
button.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
EditText mobileNum = (EditText)findViewById(R.id.mobile);
EditText message = (EditText)findViewById(R.id.message);
String mobileText = mobileNum.getText().toString();
String messagetext = message.getText().toString();
//发短信
SmsManager smsManager = SmsManager.getDefault();
//如果短信过长,超过70个汉字,拆分短信
List<String> messageList = smsManager.divideMessage(messagetext);
for(String m:messageList){
smsManager.sendTextMessage(mobileText, null, messagetext, null, null);
}
//发送完短息后,通知用户
Toast.makeText(SmsActivity.this, R.string.success, 1).show();
}
});
}
}
文章来源于网络或者作者投稿,若有侵权请联系删除,作者:老钟,如若转载,请注明出处:https://www.laoz.net/207.html