本文轉(zhuǎn)自:http://www.cnblogs.com/feisky/archive/2010/06/10/1755914.html
發(fā)送短信的方法
有兩種方法可以實現(xiàn)發(fā)送短信,其一是使用intent-startActivity,URI數(shù)據(jù)格式為"smsto:num",調(diào)用的action為Intent.ACTION_SENDTO:

Uri uri = Uri.parse("smsto:5554");
Intent it =newIntent(Intent.ACTION_SENDTO, uri);
it.putExtra("sms_body","你好。。");
startActivity(it);
其二是使用SmsManager:
EditText num=(EditText)findViewById(R.id.num);
EditText content=(EditText)findViewById(R.id.content);
String mobile=num.getText().toString();
String smstext=content.getText().toString();
//獲取SmsManager
SmsManager sms=SmsManager.getDefault();
//如果內(nèi)容大于70字,則拆分為多條
List texts=sms.divideMessage(smstext);
//逐條發(fā)送短信
for(String text:texts)
{
sms.sendTextMessage(mobile,null, text,null,null);
}
//發(fā)送結(jié)果提示
Toast.makeText(SendSMS.this,"發(fā)送成功", Toast.LENGTH_LONG).show();

二者的不同在于前者只是調(diào)用了發(fā)送界面,需要按下Send按鈕短信才發(fā)送出去,而后者則是直接發(fā)送出去。
發(fā)送SMS權(quán)限的設置:
"android.permission.SEND_SMS"/>
關于SmsManager
SDK中的介紹:Manages SMS operations such as sending data, text, and pdu SMS messages. Get this object by calling the static method SmsManager.getDefault().
方法:
public void sendTextMessage (String destinationAddress, String scAddress, String text, PendingIntent sentIntent, PendingIntent deliveryIntent)
destinationAddress: 收件人地址
scAddress: 短信中心號碼,null為默認中心號碼
sentIntent: 當消息發(fā)出時,成功或者失敗的信息報告通過PendingIntent來廣播。如果該參數(shù)為空,則發(fā)信程序會被所有位置程序檢查一遍,這樣會導致發(fā)送時間延長。
deliveryIntent: 當消息發(fā)送到收件人時,該PendingIntent會被廣播。pdu數(shù)據(jù)在狀態(tài)報告的extended data ("pdu")中。
如果收件人或者信息為空則拋出 IllegalArgumentException 。
public ArrayList divideMessage (String text)
將大于70字的短信分割為多條。
參數(shù):text????the original message. Must not be null.
返回:an ArrayList of strings that, in order, comprise the original message
sendDataMessage 參數(shù)與上類似,只是用于發(fā)送Data。
sendMultipartTextMessage發(fā)送多條短信,發(fā)送內(nèi)容必須是用divideMessage分割好了的。
打電話的方法
打電話的方法類似,所不用的是URI格式為"tel:num",而調(diào)用的action為Intent.ACTION_CALL:
EditText edit=(EditText)findViewById(R.id.DialEdit);
String num=edit.getText().toString();
if((num!=null)&&(!"".equals(num.trim())))
{
Intent intent=newIntent(Intent.ACTION_CALL,Uri.parse("tel:"+num));
startActivity(intent);
}
打電話權(quán)限的設置:
"android.permission.SEND_SMS"/>

向模擬器發(fā)短信打電話的方法
1.啟動android emulator,查看標題欄找出端口。一般是android emulator (5554),其中5554就是端口。
2.打開命令行,輸入telnet localhost 5554。程序?qū)B接到android console,返回
Android Console: type 'help' for a list of commands
OK
模擬電話打入gsm
輸入gsm call <模擬打進的電話號碼>。如:
gsm call 15555218135
模擬短信發(fā)送sms send
輸入sms send <模擬發(fā)送短信的電話> <內(nèi)容>。如:
sms send 15555218135 hello
其中,15555218135為模擬器手機號碼。