Sending 50+ problems causing a generic failure

I am developing an application in which I need to send 100+ messages. After going through several threads, I found out that the restriction on sending messages, such as 100 messages, can be sent in an hour. To do this, I divide my list of recipients into pieces and put a delay of 5 seconds between each port and a delay of 3 seconds in each message. The delay between pieces increases after each piece, and when it reaches 100 seconds, it will reset to 5 seconds. After that, it worked fine for 50 messages, but when I raise the list of recipients, it causes problems, some messages do not fall into the first place and are displayed as error messages in native.

Is there any standard way to achieve this, I may need to send more than 100 messages, how can I send several messages without any glitches at once. If I need to set a delay, then what should be the appropriate delay between pieces or messages.

Thanks in advance.

private final int MAX_SMS_IN_ONE_TIME = 10; private final int DELAY_BETWEEN_CHUNKS = 5000; public void sendMessage(arguments){ // Send long messages in chunk of 20 messages and put gap of increasing 5 seconds till 50 seconds and then reset. final Iterator iterator = messageChunks.iterator(); new Thread(new Runnable() { @Override public void run(){ int interval =1; while (iterator.hasNext()) { for (final Contact contact : (List<Contact>) iterator.next()) { sendSMS(body, contact.getmMobileNumbers().get(0)); App.trackEvent("Message", "Sent", "Messages from our sms app"); } } try { Log.i("chunk", "chunk # " + interval + " delay is " + DELAY_BETWEEN_CHUNKS); Thread.sleep(DELAY_BETWEEN_CHUNKS * interval); interval++; if (interval == 10) { interval = 1; } } catch (InterruptedException e) { e.printStackTrace(); } } } }).start(); } public void sendSMS(final String message, final String phoneNo) { try { String SENT = "com.ebryx.smscustommessagegeneration"+""+System.currentTimeMillis()+""+((int)this.getmMessageId()); Intent intentMessageASendStatus = new Intent(SENT); final PendingIntent pi = PendingIntent.getBroadcast(App.getContext(), ((int)this.getmMessageId()), intentMessageASendStatus, PendingIntent.FLAG_CANCEL_CURRENT); final ArrayList<PendingIntent> sentPI = new ArrayList<PendingIntent>(){{add(pi);}}; App.getContext().registerReceiver(new BroadcastReceiver(){ @Override public void onReceive(Context arg0, Intent arg1) { switch (getResultCode()) { case Activity.RESULT_OK: Log.i("tag","sent successfully "); break; case SmsManager.RESULT_ERROR_GENERIC_FAILURE: Log.i("tag","Generic Failure"); break; case SmsManager.RESULT_ERROR_NO_SERVICE: Log.i("tag","No service failure"); break; case SmsManager.RESULT_ERROR_NULL_PDU: break; case SmsManager.RESULT_ERROR_RADIO_OFF: Log.i("tag","Airplane mode failure"); break; } } }, new IntentFilter(SENT)); final SmsManager smsManager = SmsManager.getDefault(); final ArrayList<String> parts = smsManager.divideMessage(message); new Timer().schedule(new TimerTask() { @Override public void run() { smsManager.sendMultipartTextMessage(phoneNo, null, parts, sentPI, null); }}, 3000); } } catch (Exception e) { e.printStackTrace(); } } 
+5
source share
2 answers

You must use two broadcast receivers with pending intent for SENT and DELIVER.

After the message, you should add a callback mechanism to notify msg, and set the stat to a new message. This call must be synchronized .

  • Create a HashMap and send the method below one by one according to the delivery status that we receive in the delivery broadcast receiver.

      /** * Sends an SMS message to another device * * @param phoneNumber Number to which msg send * @param message Text message */ private void sendSMS(String phoneNumber, String message) { // Intent Filter Tags for SMS SEND and DELIVER String SENT = "SMS_SENT"; String DELIVERED = "SMS_DELIVERED"; // STEP-1___ // SEND PendingIntent PendingIntent sentPI = PendingIntent.getBroadcast(this, 0, new Intent( SENT), 0); // DELIVER PendingIntent PendingIntent deliveredPI = PendingIntent.getBroadcast(this, 0, new Intent(DELIVERED), 0); // STEP-2___ // SEND BroadcastReceiver BroadcastReceiver sendSMS = new BroadcastReceiver() { @Override public void onReceive(Context arg0, Intent arg1) { switch (getResultCode()) { case Activity.RESULT_OK: Toast.makeText(getBaseContext(), "SMS sent", Toast.LENGTH_SHORT).show(); break; case SmsManager.RESULT_ERROR_GENERIC_FAILURE: Toast.makeText(getBaseContext(), "Generic failure", Toast.LENGTH_SHORT).show(); break; case SmsManager.RESULT_ERROR_NO_SERVICE: Toast.makeText(getBaseContext(), "No service", Toast.LENGTH_SHORT).show(); break; case SmsManager.RESULT_ERROR_NULL_PDU: Toast.makeText(getBaseContext(), "Null PDU", Toast.LENGTH_SHORT).show(); break; case SmsManager.RESULT_ERROR_RADIO_OFF: Toast.makeText(getBaseContext(), "Radio off", Toast.LENGTH_SHORT).show(); break; } } }; // DELIVERY BroadcastReceiver BroadcastReceiver deliverSMS = new BroadcastReceiver() { @Override public void onReceive(Context arg0, Intent arg1) { switch (getResultCode()) { case Activity.RESULT_OK: // TODO : notify from here to send new message. // Add callback mechanism Toast.makeText(getBaseContext(), "SMS delivered", Toast.LENGTH_SHORT).show(); break; case Activity.RESULT_CANCELED: Toast.makeText(getBaseContext(), "SMS not delivered", Toast.LENGTH_SHORT).show(); break; } } }; // STEP-3___ // ---Notify when the SMS has been sent--- registerReceiver(sendSMS, new IntentFilter(SENT)); // ---Notify when the SMS has been delivered--- registerReceiver(deliverSMS, new IntentFilter(DELIVERED)); SmsManager sms = SmsManager.getDefault(); sms.sendTextMessage(phoneNumber, null, message, sentPI, deliveredPI); } } 
  • You can also delete items from your HashMap as SMS DELIVERED. This can be useful for tracking how many messages have been delivered successfully.
+4
source

It seems that the official documentation on the limits for sending SMS was not found, as I could find, and on the next site.

Unfortunately , there seems to be no public documentation from the Google Developers Team for Google Developers on this issue.

This is from May 17, 2017

The only numbers in sms limits that I could find are the Commonsware website:

SMS sending restrictions
Applications running on Android 1.x and 2.x devices are limited to sending 100 SMS messages per hour before the user starts receiving a request with each SMS message request to confirm that they really want to send it.

Applications running on Android 4.x devices are now limited to 30 SMS messages in 30 minutes ... / ...

There seems to be no way to increase this limit without being tied to the phone. If you need to change the following settings. The following will allow you to send 1000 SMS in 180,000 ms == 30 minutes.

 SMS_OUTGOING_CHECK_MAX_COUNT 1000 SMS_OUTGOING_CHECK_INTERVAL_MS 1800000 

Common (disappointing) issues with Android with varying performance on all devices also apply. One phone can work at another level with another.

This company has determined the maximum SMS capabilities for some mobile phones with their product. Limitations of sending SMS with FrontlineSync and Android . They also report that rooting the phone may be required to increase restrictions.

Related Resources:

Check SMS limit for Android packages?

Is there a limit on the number of numbers for sending SMS?

Android Java: how to send SMS and receive SMS messages and receive SMS messages dated August 30, 2017.

0
source

Source: https://habr.com/ru/post/1271104/


All Articles