How to Send Mock SMS Using ADB on an Android Emulator


In this blog, I will walk you through setting up an Android emulator, turning it on, and sending mock SMS messages using Android Debug Bridge (ADB). This guide is designed for developers who need to simulate SMS behavior for app testing. Let’s dive in!
1. Setting Up the Android Emulator (Optional)
If you already have an emulator set up, feel free to skip this section. Otherwise, follow these steps:
Install Android Studio
Download and install Android Studio from developer.android.com.
During installation, ensure the Android Virtual Device (AVD) Manager is selected.
Create an Emulator
Open Android Studio and go to Tools > Device Manager.
Click on Create Device.
Select a hardware profile (e.g., Pixel 5) and click Next.
Choose a system image (e.g., Android 13.0) and download it if not already available.
Configure the emulator settings, such as RAM and storage, and click Finish.
Now, you have an emulator ready to use.
2. Turning On the Emulator
Before sending a mock SMS, you need to start the emulator.
Using Android Studio
Open the Device Manager in Android Studio.
Click the Play button next to your emulator.
Using the Emulator Command (CLI)
Ensure the
emulator
executable is available in your PATH. It is typically located in the\\<Android SDK path>\\emulator\\
directory.Open a terminal or command prompt.
List available emulators:
<Android SDK path>/emulator/emulator -list-avds
Replace
<Android SDK path>
with the actual location of your Android SDK.Start an emulator:
<Android SDK path>/emulator/emulator -avd <emulator_name>
Replace
<emulator_name>
with the name of your emulator (e.g.,Pixel_5_API_33
).
Checking Emulator Status
Use the following command to confirm that the emulator is running:
adb devices
You should see your emulator listed with the status device
.
3. Sending a Mock SMS
ADB allows you to send mock SMS messages to an emulator, making it easy to test SMS-related features in your app.
Command to Send SMS
Use the following command to send a mock SMS:
adb emu sms send <phone_number> "<message_content>"
Example
adb emu sms send 5551234567 "Hello, this is a test message!"
5551234567
: The sender’s phone number (use any dummy number for testing).Hello, this is a test message!
: The content of the SMS.
Verify SMS on the Emulator
Open the default Messages app on the emulator.
Check the received SMS to verify that it matches the mock data you sent.
Explanation of ADB Commands
Key Commands
adb devices
Lists all connected devices and emulators.adb devices
Output example:
List of devices attached emulator-5554 device
adb emu
Sends commands to the emulator. For example, thesms send
subcommand allows sending mock SMS.adb shell
Opens a shell session on the emulator for advanced debugging.adb shell
Related Commands
Restart the Emulator:
adb emu kill <Android SDK path>/emulator/emulator -avd <emulator_name>
Clear App Data:
adb shell pm clear <package_name>
Install an APK:
adb install <path_to_apk>
Uninstall an App:
adb uninstall <package_name>
Common Issues and Troubleshooting
Command Not Found for
emulator
: Ensure theemulator
executable is in your PATH. If not, specify the full path to the executable as shown above.Emulator Not Listed in
adb devices
: Ensure the emulator is running and properly configured. Restart the ADB server:adb kill-server adb start-server
Mock SMS Not Received: Check the Messages app settings and ensure the emulator supports SMS simulation.
Conclusion
Using ADB to send mock SMS messages is a powerful tool for testing SMS-related features in Android apps. By setting up an emulator, starting it, and running simple commands, you can simulate real-world scenarios and streamline your development process.
Subscribe to my newsletter
Read articles from Anmol Singh Tuteja directly inside your inbox. Subscribe to the newsletter, and don't miss out.
Written by
