Back to project page SenqmAndroid.
The source code is released under:
GNU General Public License
If you think the Android project SenqmAndroid listed in this page is inappropriate, such as containing malicious code/tools or violating the copyright, please email info at java2s dot com, thanks.
/* * Copyright 2014 Alban GRUIN/*from ww w. ja v a 2 s .c om*/ * * This file is part of SenqmAndroid. * * SenqmAndroid is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. * * SenqmAndroid is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with SenqmAndroid. If not, see <http://www.gnu.org/licenses/>. */ package com.agrn.senqm.telephony.sms; import android.content.BroadcastReceiver; import android.content.Context; import android.content.Intent; import android.os.Bundle; import android.telephony.SmsMessage; import com.agrn.senqm.network.Message; public class SMSBroadcaster extends BroadcastReceiver { @Override public void onReceive(Context context, Intent intent) { Bundle bundle = intent.getExtras(); if(bundle != null) notifyUser(getReceivedSms(bundle), context); } private void notifyUser(SmsMessage smsMessage, Context context) { if(smsMessage == null) return; Message message = new Message("send"); message.addValue("address", smsMessage.getOriginatingAddress()); message.addValue("message", smsMessage.getMessageBody()); message.send(context); } private SmsMessage getReceivedSms(Bundle bundle) { Object[] pdus = (Object[]) bundle.get("pdus"); SmsMessage message = null; for(int i = 0; i < pdus.length; i++) message = SmsMessage.createFromPdu((byte[]) pdus[i]); return message; } }