4

We have an app that detects and receives incoming SMS messages, and then auto-responds to those messages. All of this is working great.. however there is one quirk we have noticed. On my Android phone (LG L70), it works fine to show the auto-response in the native "Messages" app. However, on a different device that we are using for testing (S4 mini), the auto response does not show. But the auto-response message actually is sent with no issues from the device.

Here is the code that sends the SMS message:

SmsManager.getDefault().sendTextMessage(message.getSenderNumber(),
            null,
            autoResponseText,
            PendingIntent.getBroadcast(this, 0, new Intent(ACTION_SMS_SENT), 0),
            null);

This has us scratching our heads, needless to say. These are new "test" phones that we bought, so they are not bogged down by other installed apps that would seemingly interfere with this kind of thing. We have tried changing all kinds of settings and even uninstalling things like Google Hangouts, etc. But no luck. For some reason, it works fine on my phone to show all the messages in the native "Messages" app, but on the other phone, it does not.

Could this be a device-specific issue? Or is it something we can address in the code? If more info or code is needed on this, I'd be glad to provide it. Thanks in advance!

svguerin3
  • 2,433
  • 3
  • 29
  • 53
  • 1
    have you used content resolver to save sent sms ?? – someone Jul 21 '14 at 16:40
  • 1
    `SmsManager` is not responsible for updating any sort of SMS inbox, outbox, or whatever. Most devices will behave like your S4 mini. – CommonsWare Jul 21 '14 at 16:49
  • @CommonsWare oh interesting, I was unaware of that. So I'm guessing there is no way to "force" it out to the "Messages" outbox/inbox? If not, that's ok, but I want to be sure before closing the lid on this particular piece of functionality. Thanks for the reply on this. – svguerin3 Jul 21 '14 at 16:52
  • @Rhth not exactly sure what you mean - I can use a ContentResolver to query the messages from the inbox, but I don't know that this helps me much for this particular issue (unless there's a way to use it to force messages back out to it?) – svguerin3 Jul 21 '14 at 16:53
  • Ofcourse SMSManager isn't responsible to update your messages,If you wan't to do so you need to use content resolver.[This](http://stackoverflow.com/questions/7677124/sending-sms-programatically-doesnt-save-it-to-sent-items) might help you – someone Jul 21 '14 at 16:55
  • Thanks! I think that will work perfect for our needs. I was unaware we could use the ContentResolver to do those types of inserts. I'll give it a try. The only thing is that I'm not sure how to detect whether a message successfully was placed out there (i.e. my phone), or if it did not (i.e. the S4 mini). I guess I may have to use the ContentResolver to query and determine that? Assuming there's not a better way? – svguerin3 Jul 21 '14 at 16:57
  • I think that works good enough.I have used it myself and it's working on my nexus5 and S3.So I don't think you would have any problem with any device – someone Jul 21 '14 at 17:04
  • This question is duplicate. [Hers][1] is the answer [1]: http://stackoverflow.com/a/13030621/2073920 – Abdul Rauf Dec 21 '14 at 16:20

1 Answers1

2

Turns out this post had the correct answer, and the comment from Rhth was indeed correct.

However, it's important to note that the code to use the ContentResolver to query and find the message did not work properly, I'm guessing because the SmsManager sends the message asynchronously and doesn't insert into the ContentResolver until completed.. so it was unable to find it yet when the code to search is called right after the SmsManager sending of the message.

I imagine with a delay of some sort, I could get in a state in which it works, but oddly enough, I didn't have to worry about it, since the code to manually insert the message via the ContentResolver works fine across both of the previously-mentioned devices! I.e. it does not duplicate the message on the device that works properly. So it kind of worked out for the best across all fronts.

Community
  • 1
  • 1
svguerin3
  • 2,433
  • 3
  • 29
  • 53