SoFunction
Updated on 2025-04-09

Android packaged text messages to gmail mailbox implementation code


package ;
import ;
import ;
import ;
import ;
import ;
import ;
import ;
import ;
import ;
import ;
import ;
import ;
import ;
public class MainActivity extends Activity {
@Override
protected void onCreate(Bundle savedInstanceState) {
(savedInstanceState);
setContentView(.activity_main);
SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM-dd");
Date curDate = new Date(());// Get the current time
Date lastDate = new Date((), (),
() - 1);
((EditText) findViewById()).setText(formatter
.format(curDate));
((EditText) findViewById()).setText(formatter
.format(lastDate));
Button btn = (Button) findViewById(.button1);
(new () {
public void onClick(View v) {
sendSms(getSmsInPhone());
}
});
// Button btn1 = (Button) findViewById(.button2);
// (new () {
// public void onClick(View v) {
// EditText txtContent = (EditText) (.editText1);
// = ().toString();
// startService(new Intent(,
// ));
// }
// });
}
private String getSmsInPhone() {
StringBuilder smsBuilder = new StringBuilder();
EditText startDatePicker = (EditText) findViewById();
EditText endDatePicker = (EditText) findViewById();
DateFormat df = new SimpleDateFormat("yyyy-MM-dd");
try {
Date startDate = (().toString());
Date endDate = (().toString());
ContentResolver cr = getContentResolver();
return (startDate, endDate, cr);
}catch(Exception e){
("Exception in getSmsInPhone", ());
}
return "";
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(, menu);
return true;
}
protected void onDestroy() {
();
ActivityManager activityMgr= (ActivityManager) (ACTIVITY_SERVICE);
(getPackageName());
}
private void sendSms(String content) {
Intent intent = new Intent(.ACTION_SEND);
("plain/text");
// ("message/rfc822") ; // Use this line on real machine
EditText txtContent = (EditText) findViewById(.editText1);
String[] strEmailReciver = new String[] { ()
.toString() };
(.EXTRA_EMAIL, strEmailReciver); // Set the recipient
EditText startDatePicker = (EditText) findViewById();
EditText endDatePicker = (EditText) findViewById();
(Intent.EXTRA_SUBJECT, "["
+ ().toString() + "to"
+ ().toString() + "]SMS backup");
(.EXTRA_TEXT, content); // Set content
startActivity((intent,
"send SMS to your mail success"));
}
}