1

I am trying to make an app which would add backed up SMSs into an android phone. I tried like it is explained in other posts on stackoverflow, but it doesn't work and i don't get any error also.

I am using Android Studio and I am Running app on Lollipop.

public void createSms(List<SMS> smsList, ContentResolver cr)
{

try
       {
        ContentValues values = new ContentValues();

        Log.d("SMS-create", "Body " + smsList.get(0).body);
        //smsList.get(0) contains SMS information
        values.put(Telephony.Sms.ADDRESS,smsList.get(0).address);
        if (smsList.get(0).date != null) 
        {
            values.put(Telephony.Sms.DATE, System.currentTimeMillis());
        }
        values.put(Telephony.Sms.READ, smsList.get(0).read);
        values.put(Telephony.Sms.BODY, "message body");
        values.put(Telephony.Sms.TYPE, Telephony.Sms.MESSAGE_TYPE_INBOX);
        values.put(Telephony.Sms.PERSON, smsList.get(0).person);
        //person contains the correct contact_id 
        values.put(Telephony.Sms.STATUS, smsList.get(0).status);
        values.put(Telephony.Sms.THREAD_ID, smsList.get(0).threadId);
        // this is the correct and valid thread id for current sms 
        Log.d("SMS-log",  Telephony.Sms.Inbox.CONTENT_URI.toString());
        Uri str = cr.insert(Telephony.Sms.Inbox.CONTENT_URI, values);
        Log.d("SMS-create", "Body successful " + str.toString());

    }
    catch (Exception ex)
    {
        ex.printStackTrace();
    }
}

output:

-com.apps.vikram.smsapp D/SMS-create﹕ Body This FREE whoCalled TXT was sent to u by Vodafone.    
-com.apps.vikram.smsapp D/SMS-log﹕ content://sms/inbox  
-com.apps.vikram.smsapp D/SMS-create﹕ Body successful content://sms/inbox/0
  • I have tried with draft and sent messages also, got same result. I
  • I have added READ_SMS and WRITE_SMS permissions to the manifest file.
  • I cant understand what's wrong.

Any advice would be appreciated. Thanks

PatJ
  • 5,996
  • 1
  • 31
  • 37
Vikram
  • 201
  • 3
  • 14
  • 1
    Is your app the default messaging app? After 4.4+ the default SMS app takes care of writing the sent messages to the sms provider, for details about how to set the app as default messaging app, see my other answer http://stackoverflow.com/a/28428277/1122828 – Devashish Mamgain Mar 09 '15 at 10:54
  • 2
    From Android 4.4 APIs release notes: "Beginning with Android 4.4, the system settings allow users to select a "default SMS app." Once selected, only the default SMS app is able to write to the SMS Provider and only the default SMS app receives the SMS_DELIVER_ACTION broadcast when the user receives an SMS or the WAP_PUSH_DELIVER_ACTION broadcast when the user receives an MMS. The default SMS app is responsible for writing details to the SMS Provider when it receives or sends a new message." – David C Adams Mar 09 '15 at 20:11

0 Answers0