开发学院手机开发Android 开发 Android模拟器互发短信 阅读

Android模拟器互发短信

 2010-09-06 08:15:00 来源:WEB开发网   
核心提示:super.onCreate(savedInstanceState);setContentView(R.layout.send);demo = this;telNum = (EditText) findViewById(R.id.telNumText_send);messageText = (EditText) fin

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();

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;

}

}

接受短信的Receiver:

Java代码

package cc.androidos.sms;

import android.content.BroadcastReceiver;

import android.content.Context;

import android.content.Intent;

import android.os.Bundle;

import android.telephony.gsm.SmsMessage;

import android.util.Log;

public class SMSReceiver extends BroadcastReceiver {

@Override

public void onReceive(Context context, Intent intent) {

上一页  1 2 3 4 5 6 7 8  下一页

Tags:Android 模拟器 短信

编辑录入:coldstar [复制链接] [打 印]
[]
  • 好
  • 好的评价 如果觉得好,就请您
      0%(0)
  • 差
  • 差的评价 如果觉得差,就请您
      0%(0)
赞助商链接