title: Saving SMS in Android
body: <p>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.</p>
  
  <p>I am using Android Studio and I am Running app on Lollipop.</p>
  
  <pre><code>public void createSms(List&lt;SMS&gt; 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();
      }
  }
  </code></pre>
  
  <p>output:</p>
  
  <pre><code>-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
  </code></pre>
  
  <ul>
  <li>I have tried with draft and sent messages also, got same result.   I</li>
  <li>I have added <code>READ_SMS</code> and <code>WRITE_SMS</code> permissions to the manifest file.  </li>
  <li>I cant understand what's wrong.</li>
  </ul>
  
  <p>Any advice would be appreciated. Thanks</p>