Here is a very simple way to send sms messages from your own application.
You can either opt in to open the default sms application and to send desired phone number and text like in this code:
Intent intent = new Intent( Intent.ACTION_VIEW, Uri.parse( "sms:" + phoneNumber ) );
intent.putExtra( "sms_body", message );
startActivity( intent );
If you want to make a sms application you will need to do the following:
Let s say you will have two edit texts. One for the phone number, and one for the message.
class MySMSApplication extends Activity
{
@Override
protected void onCreate(Bundle savedInstanceState) {
editTextPhone = (EditText) findViewById(R.id.phoneNumber);
editTextMessage = (EditText) findViewById(R.id.message);
sendBtn = (Button)findViewById(R.id.send);
sendBtn.setonclickListener(new OnClickListener(){
public void Onclick(){
sendSMS(editTextPhone.getText().toString(), editTextPhone.getText().toString());
}
});
}
private void sendSMS(String phoneNumber, String message)
{
PendingIntent pi = PendingIntent.getActivity(this, 0,
new Intent(this, Object.class), 0);
SmsManager sms = SmsManager.getDefault();
sms.sendTextMessage(phoneNumber, null, message, pi, null);
}
}
For using this you will need to add the following permission:
<uses-permission android:name="android.permission.SEND_SMS">