1

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.

T-Heron
  • 5,385
  • 7
  • 26
  • 52
Mozart
  • 2,117
  • 2
  • 20
  • 38
  • 1
    You don't need to do this as of API 19, unless your app is the default messaging app. Non-default apps have their outgoing messages saved automatically by the system. – Mike M. Mar 04 '17 at 14:20
  • 1
    yes thank you, on my old phone it does not show but on my other one the messages does show automatically in the sent folder. – Mozart Mar 04 '17 at 14:48

0 Answers0