如何发送来自不同编辑文本的多字符串短信
How to send SMS with much string from different edittext
这是我的代码
final EditText editName=(EditText)findViewById(R.id.name);
final EditText password=(EditText)findViewById(R.id.pass_login);
final EditText nohp = (EditText)findViewById(R.id.handphone);
final EditText repass =(EditText)findViewById(R.id.retype);
Button submit=(Button)findViewById(R.id.submit);
submit.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
String pswrd = password.getText().toString();
int panjangpass=pswrd.length();
String nm = editName.getText().toString();
int panjangnm=nm.trim().length();
String handphone= nohp.getText().toString();
int panjanghp=handphone.trim().length();
String rtype = repass.getText().toString();
int type=rtype.trim().length();
//String pesan=
//validasi nama
if(panjangnm==0) {
Toast.makeText(getApplication(), "Insert your name", Toast.LENGTH_SHORT).show();
}else if (panjangnm<3){
Toast.makeText(getApplication(), "Name must be more than 3 character", Toast.LENGTH_SHORT).show();
//validasi no hp harus 11-12 angka
}else if (panjanghp==0){
Toast.makeText(getApplication(), "Insert your handphone number", Toast.LENGTH_SHORT).show();
}else if (panjanghp<10 || panjanghp>12) {
Toast.makeText(getApplication(), "Your handphone number must between 10-12 number", Toast.LENGTH_SHORT).show();
//validasi password min 6
}else if (panjangpass==0){
Toast.makeText(getApplication(), "Insert your password", Toast.LENGTH_SHORT).show();
}else if (panjangpass<6){
Toast.makeText(getApplication(), "Password minimal 6 character", Toast.LENGTH_SHORT).show();
//validasi retype password, harus sama
}else if (type==0){
Toast.makeText(getApplication(), "Type your password again", Toast.LENGTH_SHORT).show();
}else if (!rtype.equals(pswrd)){
Toast.makeText(getApplication(), "Password not match", Toast.LENGTH_SHORT).show();
//else terakhir untuk kondisi jika sudah terpenuhi semua
}else{
//disini sebelum balik ke menu awal, kayaknya harus kirim ke database dulu
//getText semua inputan data, kirim
sendSMS("88170551",nm);
Toast.makeText(getApplication(), "Thank you, " + editName.getText().toString() + " for register to Human Tracker Application.", Toast.LENGTH_SHORT).show();
Intent back = new Intent(v.getContext(), Mainmenu.class);
startActivity(back);
}
}
});
}
private void sendSMS(String phoneNumber, String message){
SmsManager sms= SmsManager.getDefault();
sms.sendTextMessage(phoneNumber,null,message,null,null);
我已成功尝试使用此代码发送短信。但是我只尝试在短信中发送字符串nm,如何发送3个字符串(pswrd, nm, handphone) 到短信?所以我会收到发件人的短信,他们的密码、姓名和 phone 号码
放
nm = nm + "\n" + handphone + "\n" + pswrd;
之前
sendSMS("88170551",nm);
看起来像
nm = nm + "\n" + handphone + "\n" + pswrd;
sendSMS("88170551",nm);
这是我的代码
final EditText editName=(EditText)findViewById(R.id.name);
final EditText password=(EditText)findViewById(R.id.pass_login);
final EditText nohp = (EditText)findViewById(R.id.handphone);
final EditText repass =(EditText)findViewById(R.id.retype);
Button submit=(Button)findViewById(R.id.submit);
submit.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
String pswrd = password.getText().toString();
int panjangpass=pswrd.length();
String nm = editName.getText().toString();
int panjangnm=nm.trim().length();
String handphone= nohp.getText().toString();
int panjanghp=handphone.trim().length();
String rtype = repass.getText().toString();
int type=rtype.trim().length();
//String pesan=
//validasi nama
if(panjangnm==0) {
Toast.makeText(getApplication(), "Insert your name", Toast.LENGTH_SHORT).show();
}else if (panjangnm<3){
Toast.makeText(getApplication(), "Name must be more than 3 character", Toast.LENGTH_SHORT).show();
//validasi no hp harus 11-12 angka
}else if (panjanghp==0){
Toast.makeText(getApplication(), "Insert your handphone number", Toast.LENGTH_SHORT).show();
}else if (panjanghp<10 || panjanghp>12) {
Toast.makeText(getApplication(), "Your handphone number must between 10-12 number", Toast.LENGTH_SHORT).show();
//validasi password min 6
}else if (panjangpass==0){
Toast.makeText(getApplication(), "Insert your password", Toast.LENGTH_SHORT).show();
}else if (panjangpass<6){
Toast.makeText(getApplication(), "Password minimal 6 character", Toast.LENGTH_SHORT).show();
//validasi retype password, harus sama
}else if (type==0){
Toast.makeText(getApplication(), "Type your password again", Toast.LENGTH_SHORT).show();
}else if (!rtype.equals(pswrd)){
Toast.makeText(getApplication(), "Password not match", Toast.LENGTH_SHORT).show();
//else terakhir untuk kondisi jika sudah terpenuhi semua
}else{
//disini sebelum balik ke menu awal, kayaknya harus kirim ke database dulu
//getText semua inputan data, kirim
sendSMS("88170551",nm);
Toast.makeText(getApplication(), "Thank you, " + editName.getText().toString() + " for register to Human Tracker Application.", Toast.LENGTH_SHORT).show();
Intent back = new Intent(v.getContext(), Mainmenu.class);
startActivity(back);
}
}
});
}
private void sendSMS(String phoneNumber, String message){
SmsManager sms= SmsManager.getDefault();
sms.sendTextMessage(phoneNumber,null,message,null,null);
我已成功尝试使用此代码发送短信。但是我只尝试在短信中发送字符串nm,如何发送3个字符串(pswrd, nm, handphone) 到短信?所以我会收到发件人的短信,他们的密码、姓名和 phone 号码
放
nm = nm + "\n" + handphone + "\n" + pswrd;
之前
sendSMS("88170551",nm);
看起来像
nm = nm + "\n" + handphone + "\n" + pswrd;
sendSMS("88170551",nm);