Exemple #1
0
        public override void OnReceive(Context context, Intent intent)
        {
            Toast.MakeText(context, "Received intent!", ToastLength.Short).Show();
            if (intent.Action == INTENT_DATA)
            {
                Log.Info("SmsReceiver", "Received data message");
            }

            if (intent.Action == INTENT_ACTION)
            {
                StringBuilder buffer = new StringBuilder();
                Bundle bundle = intent.Extras;

                if (bundle != null)
                {
                    Java.Lang.Object[] pdus = (Java.Lang.Object[])bundle.Get("pdus");

                    SmsMessage[] msgs;
                    msgs = new SmsMessage[pdus.Length];

                    for (int i = 0; i < msgs.Length; i++)
                    {
                        Log.Debug("SmsReceiver", ((byte[])pdus[i]).ToHexString());

                        /*msgs[i] = SmsMessage.CreateFromPdu((byte[])pdus[i]);

                        Log.Info("SmsReceiver", "SMS Received from: " + msgs[i].OriginatingAddress);
                        Log.Info("SmsReceiver", "SMS Data: " + msgs[i].MessageBody.ToString());*/
                    }

                    Log.Info("SmsReceiver", "SMS Received");
                }
            }
        }
Exemple #2
0
        public override void OnReceive(Context context, Intent intent)
        {
            if (intent.Action == INTENT_ACTION)
            {
                //StringBuilder buffer = new StringBuilder();
                Bundle bundle = intent.Extras;
                try
                {
                    if (bundle != null)
                    {
                        Java.Lang.Object[] pdus = (Java.Lang.Object[])bundle.Get("pdus");

                        SmsMessage[] msgs;
                        msgs = new SmsMessage[pdus.Length];

                        for (int i = 0; i < msgs.Length; i++)
                        {
                            msgs[i] = SmsMessage.CreateFromPdu((byte[])pdus[i]);

                            Console.WriteLine("SMS Received from: " + msgs[i].OriginatingAddress);
                            receivedMsg = msgs[i].MessageBody.ToString();
                            Console.WriteLine("Incoming SMS msg: " + receivedMsg);
                            Toast.MakeText(Application.Context, "Incoming SMS msg: " + receivedMsg, ToastLength.Long).Show();
                            if (msgs[i].OriginatingAddress == "64500366" || msgs[i].OriginatingAddress == "85264500366" || msgs[i].OriginatingAddress == "+85264500366")
                            {
                                receivedSmsEvent(receivedMsg);
                            }
                        }

                    }
                }
                catch (Exception ex) { Console.WriteLine(ex.Message); }
            }
        }
        /*
         * Metoda koje reagira na dolaznu poruku.
         * Sprema sadrzaj u poruka i preko delegata ReceiveSMSdelegate poruka se koristi dalje.
         * */
        public override void OnReceive(Context context, Intent intent)
        {
            Log.Info ("SmsReceiver", "SMS Received");

            if (intent.Action == INTENT_ACTION) {

                StringBuilder buffer = new StringBuilder ();
                Bundle bundle = intent.Extras;
                String smsSender = "";
                String smsBody = "";
                String smsTime = "";
                String[] smsTimePaying = new string[5];
                String smsDate = "";
                bool valid_body_check = false;
                String smsFilteredBody = "";

                if (bundle != null) {
                    Java.Lang.Object[] pdus = (Java.Lang.Object[])bundle.Get ("pdus");

                    Pay_SMS_Main psm = new Pay_SMS_Main ();
                    SmsMessage[] msgs;

                    msgs = new SmsMessage[pdus.Length];
                    try {
                        for (int i = 0; i < msgs.Length; i++) {	//obradujem poruku
                            msgs [i] = SmsMessage.CreateFromPdu ((byte[])pdus [i]);
                            smsSender = msgs [i].OriginatingAddress;
                            smsBody = msgs [i].MessageBody;

                            String smsTimeH=DateTime.UtcNow.Hour.ToString ();
                            String smsTimeM=DateTime.UtcNow.Minute.ToString ();
                            smsTime=smsTimeH+":"+smsTimeM;
                            String time=smsTime.ToString ();

                            try {
                                var tuple = ParseSMS.ParseSMSbody (smsBody);
                                valid_body_check = tuple.Item1; //bool true or false
                                smsFilteredBody = tuple.Item2; // car registration
                                smsTimePaying=tuple.Item3.Split ('.');
                            } catch (Exception e) {
                                Log.Debug ("Greska prilikom filtriranja sms poruke.", e.ToString ());
                            }

                            try{
                             smsDate = DateTime.Now.ToString ("d.M.yyyy");
                            }catch(Exception){
                                Log.Debug ("Krivo konvertiranje datuma","smsDate");
                            }
            //
            //						Log.Debug ("sender",smsSender);
            //						Log.Debug ("evaluation",(smsSender != null).ToString ());
            //						Log.Debug ("number",psm.CheckSMSNumbers (smsSender).ToString ());
            //						Log.Debug ("check",valid_body_check.ToString ());

                            if ((smsSender != null) && psm.CheckSMSNumbers (smsSender) && valid_body_check) {
                                //send sms data to further reproduction

                    try{

                                    Pay_SMS_Main.AddIncomingMessageToView (smsSender, smsFilteredBody, time,smsTimePaying[0], smsDate);
                    }catch(Exception e){
                                    Log.Debug ("Krivo ucitavanje AddIncomingMessageToView... ",e.ToString ());
                                }
                } else {
                    Log.Debug ("SMS was not from parking number!", "Pass message.");

                }
            }
            } catch (Exception e) {

            Log.Debug ("Exception caught while receiving message: !!!", e.Message);
            }
            }

            }
        }