Android模拟器互发短信
2010-09-06 08:15:00 来源:WEB开发网目的:使用模拟器互发短信息,比如 5554 和 5556互发短息
关键代码:
发送短信代码:
Java代码
package cc.androidos.sms;
import android.app.Activity;
import android.app.PendingIntent;
import android.content.Intent;
import android.os.Bundle;
import android.telephony.gsm.SmsManager;
import android.util.Log;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.EditText;
/**
*
* @param demo
* :its own object.
* @param telNum
* : telephone number to send to .
* @param messageText
* : the message need to send .
* @param sendBtn
* :Button.
*
*/
public class SMSDemo extends Activity {
private static SMSDemo demo;
private EditText telNum;
private EditText messageText;
private Button sendBtn;
/**
* override the method onCreate() 1.bind the data telNum and messageText.
* 2.set the sendBtn's listener.
*/
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.send);
demo = this;
telNum = (EditText) findViewById(R.id.telNumText_send);
messageText = (EditText) findViewById(R.id.message_copntent_send);
sendBtn = (Button) findViewById(R.id.send_button_send);
/**
* 1.get the data from the input line.. 2.call the SmsManager and send
* the message.
*/
sendBtn.setOnClickListener(new OnClickListener() {
public void onClick(View v) {
String telNumStr = telNum.getText().toString();
String messageStr = messageText.getText().toString();
更多精彩
赞助商链接