Android Open Source - android-sms-rpc S M S Broadcast Receiver






From Project

Back to project page android-sms-rpc.

License

The source code is released under:

MIT License

If you think the Android project android-sms-rpc listed in this page is inappropriate, such as containing malicious code/tools or violating the copyright, please email info at java2s dot com, thanks.

Java Source Code

package tk.aquaxp.smsgate.receiver;
/*  w w w . java  2s  .com*/
import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.telephony.SmsMessage;

import tk.aquaxp.smsgate.util.RPC;

/**
 * Created by mindworm on 08/10/14.
 */
public class SMSBroadcastReceiver extends BroadcastReceiver{
    Context mContext;
    RPC myRpc = null;

    public void setRPCHandler(RPC rpc){
        myRpc = rpc;
    }

    @Override
    public void onReceive(final Context context, Intent intent) {
        mContext = context;

        if (intent.getAction().equals("android.provider.Telephony.SMS_RECEIVED")){
            Bundle bundle = intent.getExtras();
            SmsMessage[] msgs = null;
            String msg_from = "";
            if (bundle != null){
                try{
                    Object[] pdus = (Object[]) bundle.get("pdus");
                    msgs = new SmsMessage[pdus.length];
                    String message = "_";

                    for (int i = 0; i < msgs.length; i++){
                        msgs[i] = SmsMessage.createFromPdu((byte[])pdus[i]);
                        msg_from = msgs[i].getOriginatingAddress();
                        String msgBody = msgs[i].getMessageBody();

                        message += msgBody;
                    }
                    myRpc.transmitSMS(msg_from, message);
                } catch (Exception e){
                    e.printStackTrace();
                }
            }
        }
    }
}




Java Source Code List

tk.aquaxp.smsgate.ApplicationTest.java
tk.aquaxp.smsgate.activity.MainActivity.java
tk.aquaxp.smsgate.asynctask.TransmitTask.java
tk.aquaxp.smsgate.receiver.BootBroadcastReceiver.java
tk.aquaxp.smsgate.receiver.SMSBroadcastReceiver.java
tk.aquaxp.smsgate.restapi.APIServer.java
tk.aquaxp.smsgate.restapi.NanoHTTPD.java
tk.aquaxp.smsgate.service.RPCService.java
tk.aquaxp.smsgate.util.NetUtils.java
tk.aquaxp.smsgate.util.RPC.java