Этот код будет работать для всех версий Android, включая вышеуказанный kitkat (19)
public boolean saveSms(String phoneNumber, String message, String readState, String time, String folderName) {
boolean ret = false;
try {
ContentValues values = new ContentValues();
values.put("address", phoneNumber);
values.put("body", message);
values.put("read", readState); //"0" for have not read sms and "1" for have read sms
values.put("date", time);
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) {
Uri uri = Telephony.Sms.Sent.CONTENT_URI;
if(folderName.equals("inbox")){
uri = Telephony.Sms.Inbox.CONTENT_URI;
}
mActivity.getContentResolver().insert(uri, values);
}
else {
mActivity.getContentResolver().insert(Uri.parse("content://sms/" + folderName), values);
}
ret = true;
} catch (Exception ex) {
ex.printStackTrace();
ret = false;
}
return ret;
}
Как звонить
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) {
final String myPackageName = getPackageName();
if (!Telephony.Sms.getDefaultSmsPackage(this).equals(myPackageName)) {
Intent intent = new Intent(Telephony.Sms.Intents.ACTION_CHANGE_DEFAULT);
intent.putExtra(Telephony.Sms.Intents.EXTRA_PACKAGE_NAME, myPackageName);
startActivityForResult(intent, 1);
}else {
saveSms("111111", "mmmmssssggggg", "0", "", "inbox");
}
}else {
saveSms("111111", "mmmmssssggggg", "0", "", "inbox");
}
onActivityResult
@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
if (requestCode == 1) {
if (resultCode == RESULT_OK) {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) {
final String myPackageName = getPackageName();
if (Telephony.Sms.getDefaultSmsPackage(mActivity).equals(myPackageName)) {
//Write to the default sms app
saveSms("111111", "mmmmssssggggg", "0", "", "inbox");
}
}
}
}
}
Для более подробной информации или примера приложения перейдите по ссылке:
http://wisdomitsol.com/blog/android/sms/how-to-programmatically-save-sms-to-inbox-or-sent-in-android