I want to add random delay between 16 to 30 seconds in sending sms in sendSMS Function, I want to know on how to integrate delay for this function and where is the right position to add the seconds delay.
Here is Code:
private void sendSMSorUSSD(String to, String message, int simNumber, String messageId) {
if (simNumber > 2) simNumber = 2;
if (to.startsWith("*")) {
if (to.trim().endsWith("#")) {
if (ActivityCompat.checkSelfPermission(this, Manifest.permission.CALL_PHONE) != PackageManager.PERMISSION_GRANTED) {
Fungsi.log("CALL_PHONE not granted");
return;
}
Fungsi.log("USSD to " + to + " sim " + simNumber);
writeLog(messageId + " QUEUE USSD: " + to + " SIM " + simNumber, this);
queueUssd(to,(simNumber == 0) ? 1 : simNumber);
} else {
Fungsi.log("not end with #");
writeLog("USSD not end with # : " + to, this);
}
} else {
Fungsi.log("send SMS " + to);
writeLog(messageId + " SEND SMS: " + to + " SIM " + simNumber + "\n" + message, this);
if (simNumber > 0) {
SmsManager smsManager = SmsManager.getDefault();
ArrayList<String> messageList = smsManager.divideMessage(message);
boolean sukses = true;
if (messageList.size() > 1) {
// Is this the right place to put the postDelayed?
sukses = SimUtil.sendMultipartTextSMS(this, simNumber - 1, to, null, messageList);
} else {
sukses = SimUtil.sendSMS(this, simNumber - 1, to, null, message, 0);
}
} else {
Fungsi.sendSMS(to, message, this);
}
}
}