Making Android Messaging app recognize messages sent from other app
When I send an SMS message in my Android application, is it possible to make the built-in Messaging app recognize that the message was sent and show it in the appropriate thread?
Currently when my app sends a message, there is no record of it being sent. I would like the message to show up like any other开发者_StackOverflow message sent from the phone. I'm hoping for something easier than manually adding the message to the sms database.
You can use the following code to store to the same folder as Messaging app.
ContentValues values = new ContentValues();
values.put("address", phoneNumber);
values.put("body", smsText);
// Note: This uses an Android internal API to save to Sent-folder
context.getContentResolver().insert(Uri.parse("content://sms/sent"), values);
This uses some internal APIs and may brake in future releases / not work on some phones, but as I mentioned in my comment some apps with millions of installs are doing something similar.
is it possible to make the built-in Messaging app recognize that the message was sent and show it in the appropriate thread?
There is no "built-in Messaging app" in Android. While each device with SMS capability has an SMS client, only some use the Messaging app that is part of the Android open source project. Others use their own.
Regardless, they only show messages they sent. The notion of "sent" messages and "the appropriate thread" is a client concept, not an operating system concept.
I'm hoping for something easier than manually adding the message to the sms database.
There is no "sms database" in Android. You are probably thinking of the content provider from the Messaging app. Again, the Messaging app is an app, not an operating system feature, and that app is not on every device. The Messaging app's "sms database" is not documented or supported -- on the contrary, Google specifically states that it is not for your use.
精彩评论