使用SMSManager短信管理器发送短信

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();
      }
    });
  }

 

}

转载于:https://www.cnblogs.com/jiww/p/5608262.html

你可能感兴趣的:(使用SMSManager短信管理器发送短信)