mButton1.setOnClickListener( new Button.OnClickListener() { |
@Override |
public void onClick(View v) { |
/* 由EditText1取得简讯收件人电话 */ |
String strDestAddress = mEditText1.getText().toString(); |
/* 由EditText2取得简讯文字内容 */ |
String strMessage = mEditText2.getText().toString(); |
/* 建构一取得default instance的 SmsManager对象 */ |
SmsManager smsManager = SmsManager.getDefault(); |
// TODO Auto-generated method stub |
/* 检查收件人电话格式与简讯字数是否超过70字符 */ |
if (isPhoneNumberValid(strDestAddress) == true |
&& iswithin70(strMessage) == true ) { |
try { |
/* |
* 两个条件都检查通过的情况下,发送简讯 * |
* 先建构一PendingIntent对象并使用getBroadcast()方法进行Broadcast * |
* 将PendingIntent,电话,简讯文字等参数传入sendTextMessage()方法发送简讯 |
*/ |
PendingIntent mPI = PendingIntent.getBroadcast( |
EX05_03. this , 0 , new Intent(), 0 ); |
smsManager.sendTextMessage(strDestAddress, null , |
strMessage, mPI, null ); |
} catch (Exception e) { |
e.printStackTrace(); |
} |
Toast.makeText(EX05_03. this , "送出成功!!" , Toast.LENGTH_SHORT) |
.show(); |
mEditText1.setText( "" ); |
mEditText2.setText( "" ); |
} |
/* 电话格式与简讯文字不符合条件时,使用Toast告知用户检查 */ |
else { |
/* 电话格式不符 */ |
if (isPhoneNumberValid(strDestAddress) == false ) { |
/* 且字数超过70字符 */ |
if (iswithin70(strMessage) == false ) { |
Toast.makeText(EX05_03. this , |
"电话号码格式错误+短信内容超过70字,请检查!!" , |
Toast.LENGTH_SHORT).show(); |
} else { |
Toast.makeText(EX05_03. this , "电话号码格式错误,请检查!!" , |
Toast.LENGTH_SHORT).show(); |
} |
} |
/* 字数超过70字符 */ |
else if (iswithin70(strMessage) == false ) { |
Toast.makeText(EX05_03. this , "短信内容超过70字,请删除部分内容!!" , |
Toast.LENGTH_SHORT).show(); |
} |
} |
} |
}); |
初级程序员
by: ETmanwenhan 发表于:2013-04-18 16:29:51 顶(1) | 踩(0) 回复
初学者,没积分,想下载来亲手体验收下也没机会,郁闷啊!![](http://yuncode.net/Public/js/kindeditor/plugins/emoticons/images/9.gif)
网友回复
回复小蜜锋 : http://yuncode.net/help
顶(0) 踩(0) 2013-04-20 10:46:49
回复评论