-1

I had a bit of code that i used to send an sms message to a number that the user entered by pressing a button. However, when the message sends, it doesn't show up in their messaging inbox so they don't know if it exactly sent or not. Is there any way i could alter the text below to save all the sms messages to the users inbox? Thanks!

This is my code:

buttonSend.setOnClickListener(new OnClickListener() {

            @Override
            public void onClick(View v) {

              String phoneNo = textPhoneNo.getText().toString();
              String sms = textSMS.getText().toString();
              try {               
                SmsManager smsManager = SmsManager.getDefault();
                smsManager.sendTextMessage(phoneNo, null, sms, null, null);
                Toast.makeText(getApplicationContext(), "Message Sent!", Toast.LENGTH_LONG).show();} 
                catch (Exception e) {
                Toast.makeText(getApplicationContext(),
                    "Unable to send message",
                    Toast.LENGTH_LONG).show();
                e.printStackTrace();
              }

            }
        }); 
    }
user1798956
  • 53
  • 4
  • 12

1 Answers1

0

Add this method to your class

 private void addMessageToSent(String telNumber, String messageBody) {
    ContentValues sentSms = new ContentValues();
    sentSms.put("address", telNumber);
    sentSms.put("body", messageBody);

    ContentResolver contentResolver = getContentResolver();
    contentResolver.insert(Uri.parse("content://sms/sent"), sentSms);
}

Hope it helps!