Android发送短信

package android.test; 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.widget.Button; import android.widget.EditText; public class Main extends Activity { private EditText m_dest; private EditText m_msg; private Button m_sendBtn; /** Called when the activity is first created. */ @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.main); m_dest = (EditText) findViewById(R.id.destEditText); m_msg = (EditText) findViewById(R.id.msgEditText); m_sendBtn = (Button) findViewById(R.id.sendBtn); m_dest.setText("请输入手机号码"); m_msg.setText("请输入短信内容"); m_dest.setOnClickListener(new EditText.OnClickListener() { @Override public void onClick(View v) { m_dest.setText(""); } }); m_msg.setOnClickListener(new EditText.OnClickListener() { @Override public void onClick(View v) { m_msg.setText(""); } }); m_sendBtn.setOnClickListener(new Button.OnClickListener() { @Override public void onClick(View v) { String strDest = m_dest.getText().toString(); String strMsg = m_msg.getText().toString(); SmsManager smsMgr = SmsManager.getDefault(); PendingIntent pi = PendingIntent.getBroadcast(Main.this, 0, new Intent(), 0); smsMgr.sendTextMessage(strDest, null, strMsg, pi, null); } }); } }

你可能感兴趣的:(android,String,null,Class,手机,button)