android发送短信

package com.quyf.smsdemo;

import java.util.List;

import android.app.Activity;
import android.app.PendingIntent;
import android.content.Intent;
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;
import android.widget.Toast;

public class SMSActivity extends Activity {
	
	private EditText et1 ;
	private EditText et2 ;
	private Button btn;
	
	private PendingIntent pintent;
	@Override
	protected void onCreate(Bundle savedInstanceState) {
		// TODO Auto-generated method stub
		super.onCreate(savedInstanceState);
		setContentView(R.layout.main);
		
		 et1 = (EditText) findViewById(R.id.mobile);
		 et2 = (EditText) findViewById(R.id.content);
		 btn = (Button) findViewById(R.id.btn);
		 pintent = PendingIntent.getBroadcast(this, 0, new Intent(), 0);
		 btn.setOnClickListener(new OnClickListener() {
			public void onClick(View v) {
				SmsManager sm = SmsManager.getDefault();
				
				List<String> msgs=sm.divideMessage(et2.getText().toString());
				for(String msg:msgs){
					sm.sendTextMessage(et1.getText().toString(), null, msg, pintent, null);
				}
				
			}
		});
		// Toast.makeText(this, et1.getText().toString()+"成功接收信息hello", Toast.LENGTH_LONG).show();
	}
}
 
 


你可能感兴趣的:(android发送短信)