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
andWRITE_SMS
permissions to the manifest file. - I cant understand what's wrong.
Any advice would be appreciated. Thanks