package com.yanjun.sms;

import java.util.List;
import android.app.Activity;
import android.os.Bundle;
import android.telephony.SmsManager;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.EditText;

public class MainActivity extends Activity {
    
  /**
    * 发短信注意权限
    * <uses-permission android:name="android.permission.SEND_SMS"/>
    */

  EditText phonEditText, messagEditText;

  @Override
  public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.main);
    phonEditText = (EditText) findViewById(R.id.editText_number);
    messagEditText = (EditText) findViewById(R.id.editText_massage);
    Button button = (Button) findViewById(R.id.button_send);
    button.setOnClickListener(new OnClickListener() {

      public void onClick(View v) {
        // TODO Auto-generated method stub
        String phone = phonEditText.getText().toString();
        String message = messagEditText.getText().toString();
        // 发短信---取得短信管理对象---取得系统默认的管理对象
        SmsManager smsManager = SmsManager.getDefault();
        // 对短信字数的拆分---70个汉字问拆分界限
        List<String> texts = smsManager.divideMessage(message);
        // 迭代
        for (String text : texts) {
          //四个参数:手机号--短信中心号码--短信内容--判断发送成功与否的响应--对方是否收到该短信的响应
          //后两个参数暂且设置为空
          smsManager.sendTextMessage(phone, null, text, null, null);
        }
      }
    });
  }
}
 
 
布局代码
 
 
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
        android:orientation="vertical"
        android:layout_width="fill_parent"
        android:layout_height="fill_parent"
        >
        <TextView android:id="@+id/textView1" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="联系人"></TextView>
        <EditText android:layout_width="fill_parent" android:layout_height="wrap_content" android:id="@+id/editText_number" android:phoneNumber="true"></EditText>
        <TextView android:id="@+id/textView2" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="发送信息内容"></TextView>
        <EditText android:layout_width="fill_parent" android:layout_height="wrap_content" android:id="@+id/editText_massage" android:minLines="5"></EditText>
        <Button android:id="@+id/button_send" android:layout_width="fill_parent" android:text="发送" android:layout_height="wrap_content"></Button>
</LinearLayout>