To those encountering the same problem with me, I have fixed this with the help of this
So here it is
smsSentReceiver = new BroadcastReceiver() {
@Override
public void onReceive(Context ctx, Intent arg1) {
String msg = "";
switch (getResultCode()) {
case Activity.RESULT_OK:
msg = "SMS has been sent";
break;
case SmsManager.RESULT_ERROR_GENERIC_FAILURE:
msg = "Generic Failure";
break;
case SmsManager.RESULT_ERROR_NO_SERVICE:
msg = "No Service";
break;
case SmsManager.RESULT_ERROR_NULL_PDU:
msg = "Null PDU";
break;
case SmsManager.RESULT_ERROR_RADIO_OFF:
msg = "Radio Off";
break;
default:
msg = "Coordinates is null, Try again";
break;
}
Toast.makeText(ctx.getApplicationContext(), msg, Toast.LENGTH_LONG).show();
}
};
smsDeliveredReceiver = new BroadcastReceiver() {
@Override
public void onReceive(Context ctx, Intent arg1) {
String msg = "";
switch (getResultCode()) {
case Activity.RESULT_OK:
msg = "SMS Delivered";
break;
case Activity.RESULT_CANCELED:
msg = "SMS not delivered";
break;
}
Toast.makeText(ctx.getApplicationContext(), msg, Toast.LENGTH_LONG).show();
}
};
ctx.getApplicationContext()
.registerReceiver(smsSentReceiver, new IntentFilter("SMS_SENT"));
ctx.getApplicationContext()
.registerReceiver(smsDeliveredReceiver, new IntentFilter("SMS_DELIVERED"));
Conclusion: So, to register the receiver inside the BroadcastReceiver class.
Instead of registerReceiver(smsSentReceiver, new IntentFilter("SMS_SENT"));
Use context.getApplicationContext().registerReceiver(smsSentReceiver, new IntentFilter("SMS_SENT"));