import android.os.Bundle;
import android.app.Activity;
import android.app.PendingIntent;
import android.content.Intent;
import android.telephony.SmsManager;
import android.view.Menu;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.EditText;
import android.widget.Toast;

public class SendSms extends Activity {
  EditText number;
  EditText content;
  Button send;
  SmsManager sManager;

  @Override
  protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_send_sms);
    //获取SmsMnager
    sManager = SmsManager.getDefault();
    //获取程序界面上的两个文本框和按钮
    number = (EditText) findViewById(R.id.number);
    content = (EditText) findViewById(R.id.content);
    send = (Button) findViewById(R.id.send);
    //为按钮send的单击事件绑定监听器
    send.setOnClickListener(new OnClickListener() {

      @Override
      public void onClick(View v) {
        // 创建一个PendingIntent对象
        PendingIntent pi =
            PendingIntent.getActivity(SendSms.this, 0, new Intent(), 0);
        //发送短信
        sManager.sendTextMessage(number.getText().toString(),
                  null, content.getText().toString(), pi, null);
        //提示短信发送完成
        Toast.makeText(SendSms.this, "短息发送完成!", 8000).show();
      }
    });
  }

 

}

posted on 2016-06-22 19:19  奋斗青年一族  阅读(449)  评论(0编辑  收藏  举报