예제 #1
0
        public void SendSmsInBackground(string recipient, string message = null)
        {
            if (!CanSendSmsInBackground)
            {
                OnSmsDeliveryResult?.Invoke(isSuccessful: false);

                return;
            }

            message ??= string.Empty;

            _smsManager = SmsManager.Default;

            CONTEXT.RegisterReceiver(this, new IntentFilter(SMS_SENT_INTENT_ACTION));
            CONTEXT.RegisterReceiver(this, new IntentFilter(SMS_DELIVERY_INTENT_ACTION));

            IList <string> messageParts = _smsManager.DivideMessage(message);

            _numberOfSmsMessageParts = messageParts.Count;

            _numberOfDeliveredMessageParts = 0;

            var sentPendingIntents     = new List <PendingIntent>();
            var deliveryPendingIntents = new List <PendingIntent>();

            var sentPendingIntent      = PendingIntent.GetBroadcast(CONTEXT, 0, new Intent(SMS_SENT_INTENT_ACTION), 0);
            var deliveredPendingIntent = PendingIntent.GetBroadcast(CONTEXT, 0, new Intent(SMS_DELIVERY_INTENT_ACTION), 0);

            for (int i = 0; i < _numberOfSmsMessageParts; i++)
            {
                sentPendingIntents.Add(sentPendingIntent);
                deliveryPendingIntents.Add(deliveredPendingIntent);
            }

            _smsManager.SendMultipartTextMessage(recipient, null, messageParts, sentPendingIntents, deliveryPendingIntents);
        }
예제 #2
0
        private void OnReceiveAction(bool result)
        {
            UnRegisterBroadcastReceiver();

            OnSmsDeliveryResult?.Invoke(isSuccessful: result);
        }