send message between two emulator android

send message between two emulator android

send message between two emulator android

send a message between two emulator android is working same as sending a message from one mobile to another mobile. Here in case of sending a message between emulators you need to use emulator port number instead of the mobile number because emulators can be identified by their port.  Follow the steps to send a message between two or more emulators.

Step 1: Start AVD

Step 2: Again Start AVD (for example if you run AVD First time it will be assigned port like 5554 and second-time port may be 5556)

Step 3: If you want to send a message from 5554 to 5556 then you need to go to emulator 5554, Message -> Compose and write the mobile number as 5556 and message hit Send Button.

Step 4: Add following permission into your AndroidManifest.xml

<uses-permission android:name=”android.permission.SEND_SMS”/>

 

Step 5 : Write down following code and Run your project in emulator 5554

Location : src\package\

FileName : MainActivity.java

package com.example.gtu_android_prog21;

/*
*  send message between two emulator android
*
*  Create an application to send message between two emulators.
*
*/
import android.app.Activity;
import android.app.PendingIntent;
import android.content.Intent;
import android.os.Bundle;
import android.telephony.SmsManager;
import android.view.Menu;
import android.view.MenuItem;

public class MainActivity extends Activity {

PendingIntent pi;
SmsManager sms;

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);

setContentView(R.layout.activity_main);

//======================================
//    Get all pending Activity
//======================================
String msg = “android.telephony.SmsManager.STATUS_ON_ICC_SENT”;
PendingIntent piSent = PendingIntent.getBroadcast(MainActivity.this, 0,new Intent(msg), 0);

//======================================
//    Send SMS Using Default SMS Manager
//======================================
sms = SmsManager.getDefault();
sms.sendTextMessage(“5556”, null, “This is sample test message”, piSent, null);
}

@Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.main, menu);
return true;
}

@Override
public boolean onOptionsItemSelected(MenuItem item) {
// Handle action bar item clicks here. The action bar will
// automatically handle clicks on the Home/Up button, so long
// as you specify a parent activity in AndroidManifest.xml.
int id = item.getItemId();
if (id == R.id.action_settings) {
return true;
}
return super.onOptionsItemSelected(item);
}
}

 

Location : res\layout

FileName: activity_main.xml

<RelativeLayout xmlns:android=”http://schemas.android.com/apk/res/android”
xmlns:tools=”http://schemas.android.com/tools”
android:layout_width=”match_parent”
android:layout_height=”match_parent”
android:paddingBottom=”@dimen/activity_vertical_margin”
android:paddingLeft=”@dimen/activity_horizontal_margin”
android:paddingRight=”@dimen/activity_horizontal_margin”
android:paddingTop=”@dimen/activity_vertical_margin”
tools:context=”com.example.gtu_android_prog21.MainActivity” >

<TextView
android:id=”@+id/textView1″
android:layout_width=”wrap_content”
android:layout_height=”wrap_content”
android:layout_alignParentTop=”true”
android:layout_centerHorizontal=”true”
android:layout_marginTop=”45dp”
android:gravity=”center_horizontal”
android:text=”Send Message to emulators programmatically”
android:textAppearance=”?android:attr/textAppearanceLarge” />

</RelativeLayout>

 

Output 1 : Emulator Screen shot of 5554

send message between two emulator android

 

Output 2 : Emulator Screenshots of 5556

send message between two emulator android

 

 

Adarsh Patel

My Self Adarsh Suryakant Patel. Currently I am working as Assistant Professor at Parul Instiute of Engineering and Technology, MCA Department, Limda, Vadodara. Major Responsibility : * Lectures * Organizing Training and Expert Sessions for * Placement and Recruitment * Faculty Representative