Android模拟器互发短信
2010-09-06 08:15:00 来源:WEB开发网SMSDemo demo = SMSDemo.getApp();
Bundle bundle = intent.getExtras();
StringBuffer sb = new StringBuffer(5000);
Object messages[] = (Object[]) bundle.get("pdus");
SmsMessage smsMessage[] = new SmsMessage[messages.length];
for (int n = 0; n < messages.length; n++) {
smsMessage[n] = SmsMessage.createFromPdu((byte[]) messages[n]);
String address = smsMessage[n].getOriginatingAddress();
sb.append(address + ":").append(smsMessage[n].getMessageBody());
}
Log.e("message", sb.toString());
/**
* call an intent to start the activity DisplayMessage with variable
* message data.
*/
Intent i = new Intent(context, DisplayMessage.class);
i.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
i.putExtra("message", sb.toString());
context.startActivity(i);
}
}
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) {
SMSDemo demo = SMSDemo.getApp();
Bundle bundle = intent.getExtras();
StringBuffer sb = new StringBuffer(5000);
Object messages[] = (Object[]) bundle.get("pdus");
SmsMessage smsMessage[] = new SmsMessage[messages.length];
for (int n = 0; n < messages.length; n++) {
smsMessage[n] = SmsMessage.createFromPdu((byte[]) messages[n]);
String address = smsMessage[n].getOriginatingAddress();
sb.append(address + ":").append(smsMessage[n].getMessageBody());
更多精彩
赞助商链接