:
Import java. util. List;
Import android. app. Activity;
Import android. OS. Bundle;
Import android. telephony. SmsManager;
Import android. view. View;
Import android. view. View. OnClickListener;
Import android. widget. Button;
Import android. widget. EditText;
Import android. widget. Toast;
Public class SendMessageActivity extends Activity
{
Private EditText mobileEditText;
Private EditText contenText;
Private Button sendbButton;
Private Button exitButton;
/** Called when the activity is first created .*/
@ Override
Public void onCreate (Bundle savedInstanceState)
{
Super. onCreate (savedInstanceState );
SetContentView (R. layout. main );
MobileEditText = (EditText) findViewById (R. id. mobile );
ContenText = (EditText) findViewById (R. id. content );
SendbButton = (Button) findViewById (R. id. send );
ExitButton = (Button) findViewById (R. id. exit );
SendbButton. setOnClickListener (listener );
ExitButton. setOnClickListener (listener );
}
Private OnClickListener listener = new OnClickListener ()
{
@ Override
Public void onClick (View v)
{
Button button = (Button) v;
Switch (button. getId ())
{
Case R. id. send:
String mobile = mobileEditText. getText (). toString ();
String contentString = contenText. getText (). toString ();
SmsManager smsManager = SmsManager. getDefault ();
// Intent intent = new Intent ();
// Intent. setAction (Intent. ACTION_SENDTO );
// Intent. setData (Uri. parse ("smsto:" + mobile ));
If (contentString. length ()> 70)
{
List <String> contents = smsManager. divideMessage (contentString );
For (String sms: contents)
{
SmsManager. sendTextMessage (mobile, null, sms, null, null );
// Intent. putExtra ("sms_body", sms );
// SendMessageActivity. this. startActivity (intent );
}
}
Else
{
SmsManager. sendTextMessage (mobile, null, contentString, null, null );
// Intent. putExtra ("sms_body", contentString );
// SendMessageActivity. this. startActivity (intent );
}
Toast. makeText (SendMessageActivity. this, "sms sent", Toast. LENGTH_SHORT). show ();
Break;
Case R. id. exit:
Android. OS. Process. killProcess (android. OS. Process. myPid ());
Break;
Default:
Break;
}
}
};
}
Import java. util. List;
Import android. app. Activity;
Import android. OS. Bundle;
Import android. telephony. SmsManager;
Import android. view. View;
Import android. view. View. OnClickListener;
Import android. widget. Button;
Import android. widget. EditText;
Import android. widget. Toast;
Public class SendMessageActivity extends Activity
{
Private EditText mobileEditText;
Private EditText contenText;
Private Button sendbButton;
Private Button exitButton;
/** Called when the activity is first created .*/
@ Override
Public void onCreate (Bundle savedInstanceState)
{
Super. onCreate (savedInstanceState );
SetContentView (R. layout. main );
MobileEditText = (EditText) findViewById (R. id. mobile );
ContenText = (EditText) findViewById (R. id. content );
SendbButton = (Button) findViewById (R. id. send );
ExitButton = (Button) findViewById (R. id. exit );
SendbButton. setOnClickListener (listener );
ExitButton. setOnClickListener (listener );
}
Private OnClickListener listener = new OnClickListener ()
{
@ Override
Public void onClick (View v)
{
Button button = (Button) v;
Switch (button. getId ())
{
Case R. id. send:
String mobile = mobileEditText. getText (). toString ();
String contentString = contenText. getText (). toString ();
SmsManager smsManager = SmsManager. getDefault ();
// Intent intent = new Intent ();
// Intent. setAction (Intent. ACTION_SENDTO );
// Intent. setData (Uri. parse ("smsto:" + mobile ));
If (contentString. length ()> 70)
{
List <String> contents = smsManager. divideMessage (contentString );
For (String sms: contents)
{
SmsManager. sendTextMessage (mobile, null, sms, null, null );
// Intent. putExtra ("sms_body", sms );
// SendMessageActivity. this. startActivity (intent );
}
}
Else
{
SmsManager. sendTextMessage (mobile, null, contentString, null, null );
// Intent. putExtra ("sms_body", contentString );
// SendMessageActivity. this. startActivity (intent );
}
Toast. makeText (SendMessageActivity. this, "sms sent", Toast. LENGTH_SHORT). show ();
Break;
Case R. id. exit:
Android. OS. Process. killProcess (android. OS. Process. myPid ());
Break;
Default:
Break;
}
}
};
}
Main. xml file
[Java]
<? Xml version = "1.0" encoding = "UTF-8"?>
<LinearLayout xmlns: android = "http://schemas.android.com/apk/res/android"
Android: orientation = "vertical"
Android: layout_width = "fill_parent"
Android: layout_height = "fill_parent"
>
<TextView
Android: layout_width = "fill_parent"
Android: layout_height = "wrap_content"
Android: text = "Enter your mobile phone number"
/>
<EditText
Android: layout_height = "wrap_content"
Android: id = "@ + id/mobile"
Android: layout_width = "match_parent"
> </EditText>
<TextView
Android: layout_width = "wrap_content"
Android: layout_height = "wrap_content"
Android: text = "Enter text message content"
> </TextView>
<EditText
Android: layout_height = "wrap_content"
Android: layout_width = "match_parent"
Android: id = "@ + id/content"
Android: lines = "3"
> </EditText>
<Button
Android: layout_width = "wrap_content"
Android: layout_height = "wrap_content"
Android: id = "@ + id/send"
Android: text = "send SMS"
> </Button>
<Button
Android: layout_width = "wrap_content"
Android: layout_height = "wrap_content"
Android: id = "@ + id/exit"
Android: text = "Exit software"
> </Button>
</LinearLayout>
<? Xml version = "1.0" encoding = "UTF-8"?>
<LinearLayout xmlns: android = "http://schemas.android.com/apk/res/android"
Android: orientation = "vertical"
Android: layout_width = "fill_parent"
Android: layout_height = "fill_parent"
>
<TextView
Android: layout_width = "fill_parent"
Android: layout_height = "wrap_content"
Android: text = "Enter your mobile phone number"
/>
<EditText
Android: layout_height = "wrap_content"
Android: id = "@ + id/mobile"
Android: layout_width = "match_parent"
> </EditText>
<TextView
Android: layout_width = "wrap_content"
Android: layout_height = "wrap_content"
Android: text = "Enter text message content"
> </TextView>
<EditText
Android: layout_height = "wrap_content"
Android: layout_width = "match_parent"
Android: id = "@ + id/content"
Android: lines = "3"
> </EditText>
<Button
Android: layout_width = "wrap_content"
Android: layout_height = "wrap_content"
Android: id = "@ + id/send"
Android: text = "send SMS"
> </Button>
<Button
Android: layout_width = "wrap_content"
Android: layout_height = "wrap_content"
Android: id = "@ + id/exit"
Android: text = "Exit software www.2cto.com"
> </Button>
</LinearLayout>
Add permission:
<Uses-permission android: name = "android. permission. SEND_SMS"> </uses-permission>
From running snails