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

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

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

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

Tags:Android 模拟器 短信

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