Android模拟器互发短信
2010-09-06 08:15:00 来源:WEB开发网if (null != telNumStr && null != messageStr) {
SmsManager smsMgr = SmsManager.getDefault();
Intent i = new Intent("cc.androidos.smsdemo.IGNORE_ME");
PendingIntent dummyEvent = PendingIntent.getBroadcast(
SMSDemo.this, 0, i, 0);
try {
smsMgr.sendTextMessage(telNumStr, null, messageStr,
dummyEvent, dummyEvent);
} catch (Exception e) {
Log.e("SmsSending", "SendException", e);
}
} else {
showDialog(getTaskId());
}
}
});
}
/**
* get its object.
*
* @return SMSDemo
*/
public static SMSDemo getApp() {
return demo;
}
}
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) {
更多精彩
赞助商链接