Android模拟器互发短信
2010-09-06 08:15:00 来源:WEB开发网import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.EditText;
import android.widget.ProgressBar;
public class DisplayMessage extends Activity {
private EditText messageText;
private EditText messageReplyText;
private Intent intent;
private String telNum;
private String message;
private Button replyBtn;
private ProgressBar bar;
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.receiver);
messageText = (EditText) findViewById(R.id.message_get);
messageReplyText = (EditText) findViewById(R.id.message_reply);
replyBtn = (Button) findViewById(R.id.reply_button);
bar = (ProgressBar) findViewById(R.id.bar);
bar.setVisibility(ProgressBar.INVISIBLE);
intent = getIntent();
String data = intent.getStringExtra("message");
String[] str = data.split(":");
if (str.length == 2) {
telNum = str[0];
message = str[1];
}
messageText.append(data);
messageText.append(" ");
// messageText.append(" ");
replyBtn.setOnClickListener(new OnClickListener() {
public void onClick(View v) {
bar.setVisibility(ProgressBar.VISIBLE);
String replyMessage = messageReplyText.getText().toString();
SmsManager smsMgr = SmsManager.getDefault();
Intent i = new Intent("cc.androidos.smsdemo.IGNORE_ME");
PendingIntent dummyEvent = PendingIntent.getBroadcast(
DisplayMessage.this, 0, i, 0);
try {
smsMgr.sendTextMessage(telNum, null, replyMessage,
dummyEvent, dummyEvent);
messageText.append(replyMessage);
更多精彩
赞助商链接