I use the following code to send an SMS. The problem is that the application indicates that the message has been sent correctly, but it is not actually sent or appears in the list of sent SMS, and I can't find where the problem could be.
public void enviar(String numTelefono, String mensaje) {
if (mensaje.length() > 160) {
Toast.makeText(context, R.string.sms_limite_max, Toast.LENGTH_LONG).show();
return;
}
if (ActivityCompat.checkSelfPermission(context, Manifest.permission.SEND_SMS) == PackageManager.PERMISSION_GRANTED) {
try {
SmsManager smsMgrVar = SmsManager.getDefault();
smsMgrVar.sendTextMessage(numTelefono, null, mensaje, null, null);
Toast.makeText(context, R.string.sms_ok,
Toast.LENGTH_LONG).show();
} catch (Exception error) {
Toast.makeText(context, error.getMessage().toString(),
Toast.LENGTH_LONG).show();
error.printStackTrace();
}
} else {
Toast.makeText(context, R.string.sms_sin_permiso,
Toast.LENGTH_LONG).show();
}
}