Showing posts with label Sms. Show all posts
Showing posts with label Sms. Show all posts

Wednesday, July 6, 2011

Android: Amazing story about sending SMS messages from the code.

Hi,
I have 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!

Tuesday, July 5, 2011

Android send SMS messages from emulator using Telnet

Hi,
I have started to develop first Android project and will write some notes during development process.
The first note is sending sms messages from terminal.
So, There are a few steps to send messages from emulator using terminal:
  1. Start emulator (The emulator has to be started becaue you need to know port to connect). For starting emulator go to the Andriod SDK and AVD Manager->Virtual Devices->Start
  2. Start telnet. Type in console window
       1: telnet

  3. Open telnet connection to the emulator port. Type in telnet window

       1: o localhost 5554
    , where localhost name of computer where emulator is running and 5554 it is port of emulator running.

  4. Try to send message. Type in telnet window

       1: sms send 5556 Test Message
    , where 5556 is phone number, Test Message is text of message.
And that is all …