5

In a certain situation, I'd like my app to be able to "fake" an incoming SMS on the user's device, as a sort of notification. This would save me money when I'd normally use Twilio to send a text to my users but I know they already have my app. Is there any way to do this? I imagine it would have something to do with Intents and Content Providers but I don't really know where to start.

To clarify: I'm not new to Android and I do respect all of the normal Notification methods. However, my app will have an opt-in for text messages and I'd like to be able to trigger them for free rather than paying for it. This is for SMS-specific uses and not as a substitute for a normal Notification.

2
  • 1
    "as a sort of notification" like push notifications on iPhone?
    – user1486147
    Aug 17, 2012 at 23:13
  • 3
    If your objective is for your app to show a notification, show a Notification. If your objective is for your server to trigger behavior in your app, use Google Cloud Messaging. Aug 17, 2012 at 23:14

2 Answers 2

2

Yes (although I really don't support doing this) it is, in theory possible by creating and broadcasting the proper intent. Specifically, they android.provider.Telephony.SMS_RECEIVED intent will be received by anybody who is listening for SMS messages, including the default SMS application. This will in turn cause the notification to be displayed.

All of that said, I've only ever done this in a custom version of Android from within the system process. I'm really not sure if a generic application can do this (in fact, I kinda doubt it). The other caveat is that you will need to formulate your data into PDU's which represent the binary data format of an SMS message. You can look this up, but it's nontrivial.

A far better approach would be to simply have your application display a notification in the tray, the way well behaved applications are supposed to notify the users of events. Take a look at the Notification class.

1
  • 1
    blog.dev001.net/post/14085892020/… You were on the right track, the link above shows how to do it in full detail. For those reading this question later, note that you will need the BROADCAST_SMS permission.
    – Sam Stern
    Aug 18, 2012 at 3:21
1

If you install the apk named ApiDemos-debug.apk that usually comes installed with your choosen platform for the SDK, you will find an example in

<Api Demos> > App > Notification > IncomingMessage

the complete source for this package is usually under

<SDK root>/samples/android-xx/ApiDemos

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.