Android: Send SMS to Emulator

The Android emulator has support for receiving text messages. You can send a SMS to an emulator by using the command line. So the first step is:

1. Be sure you have the Telnet Client feature on
To enable the Telnet feature on windows you have to make the following steps:

  • Go to Control Panel
  • Select Programs and Features
  • And from the left panel select Turn Windows features on or off
  • And now check the Telnet Client and/or server. (Actually the Telnet Server is not necessary but I usually enable it in case that I will need it sometime). Then press the OK button.
2. Open the Command Prompt (cmd) and write the following commands:
  • Type telnet and then press enter
  • Type open localhost 5554 and then press enter. The 5554 number is the port of the emulator. Usually the emulator runs on this port but it can be also 5556 or other. So you have to choose your emulator’s port. It can be read from the emulator’s title.
  • Now type the command for sending the SMS. The command is:

 
NOTE: Notice that sometimes the command is not recognized but as you can see in the above image you can try again and that it should work.
Your emulator can receive text messages now. So as a conclusion, we can send SMS to an Android emulator, but it has some limitations though.

The functional limitations of the emulator include:
  • No support for placing or receiving actual phone calls. You can simulate phone calls (placed and received) through the emulator console, however.
  • No support for USB connections
  • No support for device-attached headphones
  • No support for determining network connected state
  • No support for determining battery charge level and AC charging state
  • No support for determining SD card insert/eject
  • No support for Bluetooth
I hope this tutorial helped you!

Android TCP Connection Tutorial

In this tutorial we will make a TCP Connection. The server will be written in Java and the client will be written in Android. Actually it will be a very simple messenger client.

Note: Now we have an enhanced version of TCP Connection here, but it’s just the code. For more details and explanations you still have to read the current tutorial. 🙂

1. Make the Server in Java
To create the server create a new project in Java and make a class called “TCPServer”. In this class put the following code:
UPDATED

UPDATE: NEW CLASS
Now create another java class and call it “ServerBoard”. In this class we will make the “messenger” UI (a very simple one) with a field where the messages will be added, a text field where the server side can enter a message and 2 buttons: one to start the connection and one to send the messages. The code is like this:

2. Create the Client in Android

  • To create the Client, create a new project and call the class that creates with the project ”   MyActivity”. 
  • After this make a new class and call it “TCPClient”
  • Now in the class TCPClient put the following code:
UPDATED
 

At the beginning of this class you have a constant SERVERIP. In this constant you have to put your computer IPv4. To do this open the commander and type ipconfig and press Enter. Then you will see your computer’s IP.

Also the SERVERPORT from this class (TCPClient) must be the same with the SERVERPORT from server class (TCPServer).

Now that the server and client classes are done, we have to set the interface a little. For this we will make a ListView in MyActivity class where we will get the messages sent and received, an EditText to enter the message from client side and a button to send the message. So let’s begin.

  • go to res – layout – main.xml and put this code in main.xml:

  • create a new xml file and call it “list_item.xml”. This will contain a TextView for the messages which will be added to the ListView. The code will look like this:

  • create a new class and call it “MyCustomAdapter”.  

UPDATED

  • And now in the MyActivity class put the following code:

  • And one last thing. Go to AndroidManifest.xml and put the internet permission just before the :

Now that the project is done we must see how it actually works

1. First, you must open the server, so run the TCPServer class, the one that is made in Java and a window called ServerBoard will appear. Press on the start button like in the picture below. Do NOT start the android project before you press the start button!

2. The server waits the client to connect now, so run the android project on the emulator and wait for the project to load.

3. After the project is loaded enter a message in the EditText and send it. Your text should appear on the ListView.
4. Now go back to the ServerBoard and send a message to the client from Android. The message from server side should appear on the ListView too.
NOTE: If you test this on a device and it’s not working, probably you should turn off all your firewall (from Windows, from antivirus) . And make sure that your device WIFI is turned on (because the android client must be on the same network as the server).
 

I hope that this tutorial helped you 🙂