I need to measure the send speed of SMS in an Android device. I'm thinking on the below approach. Please let me know if it is correct, or if there is a better solution.
Calculate the time spent sending 10 messages, and calculate the average time spent for sending each. But where is the speed amount here? Does the number of characters increase the time spent?
Here is the code I have written.
SmsManager smsManager = SmsManager.getDefault();
long startTime = System.currentTimeMillis();
smsManager.sendTextMessage("1234567890",null,text,null,null);
smsManager.sendTextMessage("1234567890",null,text,null,null);
smsManager.sendTextMessage("1234567890",null,text,null,null);
smsManager.sendTextMessage("1234567890",null,text,null,null);
smsManager.sendTextMessage("1234567890",null,text,null,null);
smsManager.sendTextMessage("1234567890",null,text,null,null);
smsManager.sendTextMessage("1234567890",null,text,null,null);
smsManager.sendTextMessage("1234567890",null,text,null,null);
smsManager.sendTextMessage("1234567890",null,text,null,null);
long endTime = System.currentTimeMillis();
long result = endTime - startTime;
The result
is 742 milliseconds, but I doubt that is correct. It means that each SMS only takes 74 milliseconds.
Typically, messages are delivered within 2 seconds. We start sending messages instantly to the networks. If you're sending a large amount (over 100,000 at once), it's possible to setup a throughput of up to 30k messages/minute. If high throughput is important to you, contact us to discuss your requirements.
This is Expert Verified Answer The fastest way of sending mails is through the email. The Email is a methodology that enables the exchange of information between parties through the use of devices with electronic capacity.
TL;DR: As a good rule of thumb, you can send at least 1 text message a week, with a maximum of 10-12 messages a month. But of course, it depends on many factors, so let's dig deeper.
The sendTextMessage()
method takes for its fourth parameter a PendingIntent
that will fire when the message is sent. We can attach the current system time as an extra to the Intent
for that PendingIntent
, and when it fires, retrieve that extra and compare it to the current system time then. This will give us a decent measure of how long it takes to actually send the message.
We'll use a BroadcastReceiver
to handle the PendingIntent
, simply retrieving the sent time extra in its onReceive()
, and figuring the elapsed time from the current time there.
BroadcastReceiver smsSendReceiver = new BroadcastReceiver() {
@Override
public void onReceive(Context context, Intent intent) {
long sentTime = intent.getLongExtra("sent_time", 0);
long elapsedTime = System.currentTimeMillis() - sentTime;
Toast.makeText(context, elapsedTime + "ms", Toast.LENGTH_SHORT).show();
}
};
We need to register this Receiver before we send the message. In an Activity
or Service
:
registerReceiver(smsSendReceiver, new IntentFilter("SMS_SENT"));
In sending our message, we'll kinda "cram" the PendingIntent
construction right into the sendTextMessage()
call, so we don't inadvertently introduce any unnecessary delay between grabbing the current time, and actually making the call.
SmsManager sm = SmsManager.getDefault();
sm.sendTextMessage("1234567890",
null,
"Testing...",
PendingIntent.getBroadcast(this,
0,
new Intent("SMS_SENT")
.putExtra("sent_time",
System.currentTimeMillis()),
0),
null);
If desired, this can be run multiple times, and an average figured from the results. Be sure to handle the PendingIntent
s appropriately if doing so, to ensure that the correct send time is delivered for each broadcast. In the given example, an easy way to do this is to use a different request code - the second argument in getBroadcast()
- for each call.
It is advisable to unregister the Receiver when you're done with it, lest you get a nasty message in your logs about a leaked Receiver.
unregisterReceiver(smsSendReceiver);
Set Broadcast Receiver and update time once you got SMS SENT msg . then calculate each sms sent time . link may help Android SMS Delivery Intent always return -1
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With