0

I sending message using SMSManager, I can able to send the message but I want to save it in a message conversation (Default Message Application in Device)?

What i did is

ContentValues values = new ContentValues();
values.put("address", "123456789");
values.put("body", "foo bar");
getContentResolver().insert(Uri.parse("content://sms/sent"), values);

I can able to add it in the inbox but

As CommansWare comment from here,

The SMS content provider is not part of the Android SDK. Your code will break on devices that replace the SMS client with their own. Your code may break in future versions of Android

I dont have device to test in latest version, What will be the solution for all the version of android?

Community
  • 1
  • 1
kumar_android
  • 2,273
  • 1
  • 21
  • 30
  • 2
    Since it's not part of android sdk, you'll need to change your code if content provider will be changed. So the best solution would be to add some update system to your application. When device updates to a version that has different provider, notify user about it and if you create new app that handles changes ask your customer to download one. – Leri Feb 20 '13 at 07:14
  • From this [link](https://stackoverflow.com/questions/642076/how-to-save-sms-to-inbox-in-android) is a working answer by Pir Fahim Shah. – Antony Kavoo Sep 18 '21 at 21:18

1 Answers1

1

The content uri is not part of Android sdk. Although I haven't seen any devices that use alternative uri for sms provider, but it could be one. I think there is tiny possibility that Google will change this uri string to another one in the future. But vendor can also modify this. So generally there are no silver bullet for all the versions of Android.

As PLB said, you can add some updating and bug reporting feature to your application. When device updates to a version that has different provider, notify user about it and if you create new app that handles changes ask your customer to download one. And if your code fail to read/write the current uri. Report some information about the device to you. So you will be able to fix it up.

I first thought that maybe you can automatically look up the bytecode(dex bytecode) of the com.android.providers.telephony.SmsProvider. However, this is not part of Android sdk too.

StarPinkER
  • 14,081
  • 7
  • 55
  • 81