Pages

Sunday, December 4, 2011

Android: Using AlarmManager to Send SMS to Same Phone

I was working with sending scheduled SMS to the user's phone for my latest app and I found this code to do it after hours of using Google. However, I have slightly modified the code to fit my needs. This code emulate almost perfectly an actual sms received by the phone but remember that every phone does this differently. I'm just taking the assumption that most users still use stock messaging app.





First, create the interface.

main.xml

» Click to show Code - click again to hide... «

AndroidAlarmSMSActivity.java

» Click to show Code - click again to hide... «


SmsAlarmService.java

» Click to show Code - click again to hide... «

Modify AndroidManifest.xml to add <service android:name=".MyAlarmService" />
Permisssions needed is VIBRATE, WRITE_SMS, READ_SMS, SEND_SMS.

» Click to show Code - click again to hide... «

Ten seconds later, the message will be written to the phone inbox. The push notification is made. Pressing the notification will go to the default messaging app.