I'm developing an Android app that fetch client mobile and send an SMS in the background; I want the sent messages to appear in the native SMS app. This is my code and it works fine sending the message.
public class AlarmReceiver extends BroadcastReceiver {
@Override
public void onReceive(Context context, Intent intent) {
// For our recurring task, we'll just display a message
Toast.makeText(context, "I'm running from AlarmReceiver", Toast.LENGTH_SHORT).show();
//
String no = "70625783";
String msg = "message";
//Getting intent and PendingIntent instance
Intent i = new Intent(context, MainActivity.class);
PendingIntent pi = PendingIntent.getActivity(context, 0, i, 0);
//Get the SmsManager instance and call the sendTextMessage method to send message
SmsManager sms = SmsManager.getDefault();
sms.sendTextMessage(no, null, msg, pi, null);
Toast.makeText(context, "Message Sent successfully!",
Toast.LENGTH_LONG).show();
}
}
For simplicity I have hard-coded the mobile and the message content.