sms.xmlFile
<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=".MainActivity" >
<EditText
android:id="@+id/phnNo"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:layout_centerHorizontal="true"
android:layout_marginTop="35dp"
android:ems="10"
android:inputType="phone"
android:hint="Please Enter Phone No">
<requestFocus />
</EditText>
<EditText
android:id="@+id/msgcontent"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignLeft="@+id/phnNo"
android:layout_below="@+id/phnNo"
android:layout_marginTop="63dp"
android:ems="10"
android:hint="Please Write MSG"/>
<Button
android:id="@+id/send"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@+id/msgcontent"
android:layout_centerHorizontal="true"
android:layout_marginTop="75dp"
android:text="SEND_MSG" />
</RelativeLayout>
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=".MainActivity" >
<EditText
android:id="@+id/phnNo"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:layout_centerHorizontal="true"
android:layout_marginTop="35dp"
android:ems="10"
android:inputType="phone"
android:hint="Please Enter Phone No">
<requestFocus />
</EditText>
<EditText
android:id="@+id/msgcontent"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignLeft="@+id/phnNo"
android:layout_below="@+id/phnNo"
android:layout_marginTop="63dp"
android:ems="10"
android:hint="Please Write MSG"/>
<Button
android:id="@+id/send"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@+id/msgcontent"
android:layout_centerHorizontal="true"
android:layout_marginTop="75dp"
android:text="SEND_MSG" />
</RelativeLayout>
SMS.javaFile
package com.example.sendsms;
import android.app.Activity;
import android.os.Bundle;
import android.telephony.gsm.SmsManager;
import android.telephony.gsm.SmsMessage;
import android.view.Menu;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.Toast;
public class MainActivity extends Activity {
Button sendmsg;
EditText phone,msg;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
sendmsg=(Button)findViewById(R.id.send);
phone=(EditText)findViewById(R.id.phnNo);
msg=(EditText)findViewById(R.id.msgcontent);
final SmsManager sms=SmsManager.getDefault();
sendmsg.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
// TODO Auto-generated method stub
sms.sendTextMessage(phone.getText().toString(),null, msg.getText().toString(), null, null);
Toast.makeText(getApplicationContext(), "Successfully msg send", Toast.LENGTH_LONG).show();
}
});
}
@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;
}
}
import android.app.Activity;
import android.os.Bundle;
import android.telephony.gsm.SmsManager;
import android.telephony.gsm.SmsMessage;
import android.view.Menu;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.Toast;
public class MainActivity extends Activity {
Button sendmsg;
EditText phone,msg;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
sendmsg=(Button)findViewById(R.id.send);
phone=(EditText)findViewById(R.id.phnNo);
msg=(EditText)findViewById(R.id.msgcontent);
final SmsManager sms=SmsManager.getDefault();
sendmsg.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
// TODO Auto-generated method stub
sms.sendTextMessage(phone.getText().toString(),null, msg.getText().toString(), null, null);
Toast.makeText(getApplicationContext(), "Successfully msg send", Toast.LENGTH_LONG).show();
}
});
}
@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;
}
}
SMS Avtivity output:-
->User can used this tutorial to send a message to another phone in android app.