@Override
public void onReceive(Context context, Intent intent) {
if (intent.getAction().equals(SMS_RECEIVED)) {
Log.d(TAG, "sms received");
Bundle bundle = intent.getExtras();
// get sms objects
Object[] pdus = (Object[]) bundle.get("pdus");
if (pdus.length == 0) {
return;
}
// large message might be broken into many
SmsMessage[] messages = new SmsMessage[pdus.length];
StringBuilder sb = new StringBuilder();
for (int i = 0; i < pdus.length; i++) {
messages[i] = SmsMessage.createFromPdu((byte[]) pdus[i]);
sb.append(messages[i].getMessageBody());
}
String sender = messages[0].getOriginatingAddress();
String message = sb.toString();
SMessage sMessage = new SMessage(sender, message);
SmsObservable.getInstance().updateValue(sMessage);
}
}
SmsReceiver.java 文件源码
java
阅读 23
收藏 0
点赞 0
评论 0
项目:BTNotifierAndroid
作者:
评论列表
文章目录