1. First create two emulators
One should be emulator-5554 and the other one should be emulator-5556
2. Here is the Activity code for send SMS using intent.
import android.app.Activity; import android.content.Intent; import android.net.Uri; import android.os.Bundle; public class TestSMSActivity extends Activity { /** Called when the activity is first created. */ @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.main); String number = "5556"; startActivity(new Intent(Intent.ACTION_VIEW, Uri.fromParts("sms", number, null))); } }
The variable "number" in line 11 is the the recipient of the SMS activity. I'm going test this application using two emulators therefore I used one emulator number for that variable. If you are going to send SMS to mobile phone replace number with mobile phone number, but remember that sending SMS from emulator to a cell phone is difficult.
Don't forget to add send SMS permission to your Manifest file.
3. Run the project.
Android device chooser window will appear. Choose an AVD. If you assigned 5556 to number variable then choose emulator-5554 to run program, other vice select emulator-5554.
Then compose message window will open. Type a simple text (Eg:-"Hello world!") there and click on send.
emulator-5554
You can see received SMS on the other emulator
emulator-5556