SmsActivity. java
[Java]
Package com. example. lession01_sms;
Import java. util. ArrayList;
Import android.net. Uri;
Import android. OS. Bundle;
Import android. app. Activity;
Import android. app. PendingIntent;
Import android. content. Intent;
Import android. telephony. SmsManager;
Import android. view. Menu;
Import android. view. View;
Import android. widget. Button;
Import android. widget. EditText;
Import android. widget. Toast;
Public class SmsActivity extends Activity {
// Declare the control object
Public Button btn_send;
Public EditText edit_num;
Public EditText edit_content;
@ Override
Protected void onCreate (Bundle savedInstanceState ){
Super. onCreate (savedInstanceState );
// Set the displayed view (layout file)
SetContentView (R. layout. activity_sms );
Btn_send = (Button) findViewById (R. id. button_send );
Edit_num = (EditText) findViewById (R. id. edit_num );
Edit_content = (EditText) findViewById (R. id. edit_content );
Btn_send.setOnClickListener (new View. OnClickListener (){
@ Override
Public void onClick (View v ){
/**
* Send MMS
*/
// Obtain the phone number
String phone_num = edit_num.getText (). toString ();
// Obtain the sent content
String phone_content = edit_content.getText (). toString ();
// Create intent object
Intent intent = new Intent (Intent. ACTION_SEND );
Intent. putExtra (Intent. EXTRA_STREAM, Uri. parse ("file: // sdcard/1.jpg"); // uri of your attachment
Intent. putExtra ("address", phone_num); // The destination number for sending MMS messages.
Intent. putExtra ("exit_on_sent", true );
Intent. putExtra ("subject", "subject: I love you"); // subject of MMS
Intent. putExtra ("sms_body", "content: XXXX"); // text in MMS
Intent. setType ("image/*"); // MMS attachment type
SmsActivity. this. startActivity (intent );
}
});
}
@ Override
Public boolean onCreateOptionsMenu (Menu menu ){
// Inflate the menu; this adds items to the action bar if it is present.
GetMenuInflater (). inflate (R. menu. sms, menu );
Return true;
}
Public void send (){
// Obtain the control object
Btn_send = (Button) findViewById (R. id. button_send );
Edit_num = (EditText) findViewById (R. id. edit_num );
Edit_content = (EditText) findViewById (R. id. edit_content );
// Register events for button controls
Btn_send.setOnClickListener (new View. OnClickListener (){
@ Override
Public void onClick (View arg0 ){
// Obtain the phone number
String phone_num = edit_num.getText (). toString ();
// Obtain the sent content
String phone_content = edit_content.getText (). toString ();
// Obtain the text message manager object
SmsManager smsManager = SmsManager. getDefault ();
// Intent object
PendingIntent pendingIntent = PendingIntent. getBroadcast (
SmsActivity. this, 0, new Intent (), 0 );
// 70 pages
ArrayList <String> contents = smsManager. divideMessage (phone_content );
For (String c: contents ){
SmsManager. sendTextMessage (phone_num, null, c, pendingIntent, null );
}
// Toast Effect
Toast. makeText (SmsActivity. this, "sent", Toast. LENGTH_LONG)
. Show ();
}
});
}
/* Public static void sendMMS (final Context context, String number,
String subject, String text, String imagePath, String audioPath ){
Final MMSInfo mmsInfo = new MMSInfo (context, number, subject, text,
ImagePath, audioPath );
Final List <String> list = APNManager. getSimMNC (context );
New Thread (){
@ Override
Public void run (){
Try {
Byte [] res = MMSSender. sendMMS (context, list,
MmsInfo. getMMSBytes ());
} Catch (Exception e ){
// TODO Auto-generated catch block
E. printStackTrace ();
}
};
}. Start ();
}*/
}
Package com. example. lession01_sms;
Import java. util. ArrayList;
Import android.net. Uri;
Import android. OS. Bundle;
Import android. app. Activity;
Import android. app. PendingIntent;
Import android. content. Intent;
Import android. telephony. SmsManager;
Import android. view. Menu;
Import android. view. View;
Import android. widget. Button;
Import android. widget. EditText;
Import android. widget. Toast;
Public class SmsActivity extends Activity {
// Declare the control object
Public Button btn_send;
Public EditText edit_num;
Public EditText edit_content;
@ Override
Protected void onCreate (Bundle savedInstanceState ){
Super. onCreate (savedInstanceState );
// Set the displayed view (layout file)
SetContentView (R. layout. activity_sms );
Btn_send = (Button) findViewById (R. id. button_send );
Edit_num = (EditText) findViewById (R. id. edit_num );
Edit_content = (EditText) findViewById (R. id. edit_content );
Btn_send.setOnClickListener (new View. OnClickListener (){
@ Override
Public void onClick (View v ){
/**
* Send MMS
*/
// Obtain the phone number
String phone_num = edit_num.getText (). toString ();
// Obtain the sent content
String phone_content = edit_content.getText (). toString ();
// Create intent object
Intent intent = new Intent (Intent. ACTION_SEND );
Intent. putExtra (Intent. EXTRA_STREAM, Uri. parse ("file: // sdcard/1.jpg"); // uri of your attachment
Intent. putExtra ("address", phone_num); // The destination number for sending MMS messages.
Intent. putExtra ("exit_on_sent", true );
Intent. putExtra ("subject", "subject: I love you"); // subject of MMS
Intent. putExtra ("sms_body", "content: XXXX"); // text in MMS
Intent. setType ("image/*"); // MMS attachment type
SmsActivity. this. startActivity (intent );
}
});
}
@ Override
Public boolean onCreateOptionsMenu (Menu menu ){
// Inflate the menu; this adds items to the action bar if it is present.
GetMenuInflater (). inflate (R. menu. sms, menu );
Return true;
}
Public void send (){
// Obtain the control object
Btn_send = (Button) findViewById (R. id. button_send );
Edit_num = (EditText) findViewById (R. id. edit_num );
Edit_content = (EditText) findViewById (R. id. edit_content );
// Register events for button controls
Btn_send.setOnClickListener (new View. OnClickListener (){
@ Override
Public void onClick (View arg0 ){
// Obtain the phone number
String phone_num = edit_num.getText (). toString ();
// Obtain the sent content
String phone_content = edit_content.getText (). toString ();
// Obtain the text message manager object
SmsManager smsManager = SmsManager. getDefault ();
// Intent object
PendingIntent pendingIntent = PendingIntent. getBroadcast (
SmsActivity. this, 0, new Intent (), 0 );
// 70 pages
ArrayList <String> contents = smsManager. divideMessage (phone_content );
For (String c: contents ){
SmsManager. sendTextMessage (phone_num, null, c, pendingIntent, null );
}
// Toast Effect
Toast. makeText (SmsActivity. this, "sent", Toast. LENGTH_LONG)
. Show ();
}
});
}
/* Public static void sendMMS (final Context context, String number,
String subject, String text, String imagePath, String audioPath ){
Final MMSInfo mmsInfo = new MMSInfo (context, number, subject, text,
ImagePath, audioPath );
Final List <String> list = APNManager. getSimMNC (context );
New Thread (){
@ Override
Public void run (){
Try {
Byte [] res = MMSSender. sendMMS (context, list,
MmsInfo. getMMSBytes ());
} Catch (Exception e ){
// TODO Auto-generated catch block
E. printStackTrace ();
}
};
}. Start ();
}*/
}