Android: Amazing Story about Sending SMS Messages from the Code

I’ve found amazing case of sending sms messages from the code.

Task
I need to send SMS message from my test method and test behavior of parsing it. Just for this post we are interesting in first part: Sending SMS message from code.
I’ve written next simple code:

final SmsManager smsManager = SmsManager.getDefault();
smsManager.sendTextMessage(“5554”, null, “Test”, null, null);

and tried to test it. Just put this code in simple test method and run Android Unit Test. The result is … nothing!!! Why?!! I did not understand …

Solution
After hours of investigation and reading documentation and blogs I decided to try the same manipulation, BUT, just on two emulators. I have started two emulators on 5554 and 5556 and tried start test project on 5554 but send message to 5556. Simple changes in code below:

final SmsManager smsManager = SmsManager.getDefault();
smsManager.sendTextMessage(“5556”, null, “Test”, null, null);

And … and … I was surprised, I can see message “Test” on 5556 emulator and it is perfectly!
Cheers!

READ  Fancybox on ASP.net Web Forms

Leave a Reply

Your email address will not be published. Required fields are marked *