二、界面设计
绘制如下界面:

三、代码编写
为了实现通信功能,我们需要引入代码包:import android.telephony.gsm.SmsManager;
在按钮的响应中添加:

1.在这个程序中,我们用到了sendTextMessage函数,从sdk中查到:
public void sendTextMessage (String destinationAddress, String scAddress, String text, PendingIntent sentIntent, PendingIntent deliveryIntent)
destinationAddress 收件人地址
scAddress 短信中心号码,空为默认中心号码
sentIntent 当消息发出时,成功或者失败的信息报告通过PendingIntent来广播。如果该参数为空,则发信程序会被所有位置程序检查一遍,这样会导致发送时间延长。
deliveryIntent 当消息发送到收件人时,该PendingIntent会被广播。pdu数据在状态报告的extended data ("pdu")中。
抛出 IllegalArgumentException 如果收件人或者信息为空。
2.
public static PendingIntent getBroadcast (Context context, int requestCode, Intent intent, int flags)
返回一个用于广播的PendingIntent,类似于调用Context.sendBroadcast()函数
requestCode 暂时不用
intent 是用于广播的intent
flag 有:FLAG_ONE_SHOT, FLAG_NO_CREATE, FLAG_CANCEL_CURRENT, FLAG_UPDATE_CURRENT 用于设置新建的PendingIntent是使用一次、如无则不创建、取消当前、更新当前等属性。