Search code examples
androidandroid-intentsmsmanager

Updating sent SMS in default app thread


I have developed an app in which I send an SMS upon a certain event. I have experimented with the following two methods:

Method 1:

SmsManager sms = SmsManager.getDefault();
                     sms.sendTextMessage(srcNumber, null, message, null, null);

Method 2:

Intent intent = new Intent( Intent.ACTION_VIEW, Uri.parse( "sms:" + srcNumber)); 
                    intent.putExtra( "sms_body", message ); 
                    startActivity(intent);

My requirements are:

1) The SMS should be sent without opening the phone's default SMS app.

2) The sent SMS should appear in the message thread in the default message app.

Method 1 satisfies requirement 1 and Method 2 satisfies requirement 2. Is there any way to satisfy both my requirements?


Solution

  • SmsManager sms = SmsManager.getDefault();
                         sms.sendTextMessage(srcNumber, null, message, null, null);
    
    
    ContentValues values = new ContentValues();
    values.put("address", srcNumber);
    values.put("body", message);
    getContentResolver().insert(Uri.parse("content://sms/sent"), values);
    

    This should solve it.

    NOTE: This requires android.permission.WRITE_SMS permission