Skip to content

Commit

Permalink
Retry Failed sms After 10 second for 3 times
Browse files Browse the repository at this point in the history
  • Loading branch information
ibnux committed Jun 7, 2022
1 parent 77bf237 commit 802fe2c
Show file tree
Hide file tree
Showing 3 changed files with 45 additions and 10 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ to compile yourself, you need your own Firebase
- DELIVERED NOTIFICATION to SERVER
- USSD
- MULTIPLE SIMCARD
- RETRY SMS FAILED TO SENT 3 TIMES

## USSD Request

Expand Down
26 changes: 21 additions & 5 deletions app/src/main/java/com/ibnux/smsgateway/Utils/SimUtil.java
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@

public class SimUtil {

public static boolean sendSMS(Context ctx, int simID, String toNum, String centerNum, String smsText) {
public static boolean sendSMS(Context ctx, int simID, String toNum, String centerNum, String smsText, int retry) {
String name;

try {
Expand All @@ -39,10 +39,18 @@ public static boolean sendSMS(Context ctx, int simID, String toNum, String cente

Intent is = new Intent(Fungsi.SENT);
is.putExtra("number",toNum);
is.putExtra("centerNum",centerNum);
is.putExtra("simID",simID);
is.putExtra("smsText",smsText);
is.putExtra("retry",retry);
PendingIntent sentPI = PendingIntent.getBroadcast(ctx, time,
is, 0);
Intent id = new Intent(Fungsi.DELIVERED);
id.putExtra("number",toNum);
is.putExtra("number",toNum);
is.putExtra("centerNum",centerNum);
is.putExtra("simID",simID);
is.putExtra("smsText",smsText);
is.putExtra("retry",retry);
PendingIntent deliveredPI = PendingIntent.getBroadcast(ctx, time,
id, 0);

Expand Down Expand Up @@ -124,17 +132,25 @@ public static boolean sendMultipartTextSMS(Context ctx, int simID, String toNum,
String sms = "";
for(int n=0;n<smsTextlist.size();n++) {
int time = (int) System.currentTimeMillis()/1000;
sms += smsTextlist.get(n);

Intent is = new Intent(Fungsi.SENT);
is.putExtra("number", toNum);
is.putExtra("number",toNum);
is.putExtra("centerNum",centerNum);
is.putExtra("simID",simID);
is.putExtra("smsText",sms);
is.putExtra("retry",0);
sentIntentList.add(PendingIntent.getBroadcast(ctx, time+n,
is, 0));

Intent id = new Intent(Fungsi.DELIVERED);
id.putExtra("number", toNum);
is.putExtra("number",toNum);
is.putExtra("centerNum",centerNum);
is.putExtra("simID",simID);
is.putExtra("smsText",sms);
is.putExtra("retry",0);
deliveryIntentList.add(PendingIntent.getBroadcast(ctx, time+n,
id, 0));
sms += smsTextlist.get(n);
}

method = Class.forName("com.android.internal.telephony.ISms$Stub").getDeclaredMethod("asInterface", IBinder.class);
Expand Down
28 changes: 23 additions & 5 deletions app/src/main/java/com/ibnux/smsgateway/layanan/PushService.java
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,28 @@ public void onReceive(Context arg0, Intent arg1) {
msg = "Radio off";
break;
}

// RETRY AFTER 10 SECOND IF FAILED UNTIL 3 TIMES
if(msg!=null && !msg.equals("success")){
int retry = arg1.getIntExtra("retry",0);
if(retry<3){
new Handler().postDelayed(new Runnable() {
@Override
public void run() {
String number = arg1.getStringExtra("number");
int simID = arg1.getIntExtra("simID",0);
String centerNum = arg1.getStringExtra("centerNum");
String smsText = arg1.getStringExtra("smsText");
int retry = arg1.getIntExtra("retry",0);
retry++;
SimUtil.sendSMS(context,simID,number,centerNum,smsText,retry);
}
}, 10000);

return;
}
}

if (msg != null) {
Calendar cal = Calendar.getInstance();
writeLog("SENT: " + msg + " : " + arg1.getStringExtra("number"), arg0);
Expand Down Expand Up @@ -241,12 +263,8 @@ private void sendSMSorUSSD(String to, String message, int simNumber, String mess
if (messageList.size() > 1) {
sukses = SimUtil.sendMultipartTextSMS(this, simNumber - 1, to, null, messageList);
} else {
sukses = SimUtil.sendSMS(this, simNumber - 1, to, null, message);
sukses = SimUtil.sendSMS(this, simNumber - 1, to, null, message, 0);
}
// if(!sukses){
// Fungsi.log("Try sending using internal API");
// Fungsi.sendSMS(to, message, this);
// }
} else {
Fungsi.sendSMS(to, message, this);
}
Expand Down

0 comments on commit 802fe2c

Please sign in to comment.