在发送直接短信时没有问题,但是当我发送包含SMS
的操作DNA bases(A , G , T , C only)
时,它就无法正常工作。
纯文本是正常消息。有什么问题??请帮忙。
public class sendMessage extends Activity {
Button button;
EditText plainTxt;
EditText cipherText;
EditText editPhoneNum;
int plaintxtArray[] = new int[1500];
Bundle bundle=new Bundle();
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.smssend);
button = (Button) findViewById(R.id.button);
editPhoneNum = (EditText)findViewById(R.id.editPhoneNum);
plainTxt = (EditText) findViewById(R.id.editSMS);
cipherText = (EditText)findViewById(R.id.editcipher);
button.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
String phoneNo = editPhoneNum.getText().toString();
//Toast.makeText(getBaseContext(), "Number is: " + phoneNo, Toast.LENGTH_LONG).show();
String plainText = plainTxt.getText().toString();
String CipherText=DNAbaseConvert(plainText);
Toast.makeText(getBaseContext(), "Cypher Text is: " + CipherText, Toast.LENGTH_LONG).show();
MessageToSent( phoneNo, CipherText);
}
});
}
public String DNAbaseConvert(String plainText)
{
//various operation goes here.
return b; //b-> a string , length 7-8 charecter long.
}
public void MessageToSent(String phoneNo, String CipherText) {
try {
SmsManager smsManager = SmsManager.getDefault();
smsManager.sendTextMessage(phoneNo, null, CipherText, null, null);
Toast.makeText(getApplicationContext(), "SMS Sent!",
Toast.LENGTH_LONG).show();
} catch (Exception e) {
Toast.makeText(getApplicationContext(),
"SMS faild, please try again later!",
Toast.LENGTH_LONG).show();
e.printStackTrace();
}
}
public void onBackPressed() {
super.onBackPressed();
Intent www = new Intent(sendMessage.this, LoggedIn1.class);
startActivity(www);
finish();
}
}
答案 0 :(得分:1)
尝试将DNAbaseConvert(plainText)
中的响应保存在变量中,并将其传递给sendTextMessage()
String msg=DNAbaseConvert(plainText);
smsManager.sendTextMessage(phoneNo, null, msg, null, null);
这是因为来自DNAbaseConvert()的响应可能会在其中引起问题..
答案 1 :(得分:1)
您可能在遇到SMS消息大小限制时遇到问题。如果您使用的是SmsManager.sendTextMessage()
方法,则可以尝试SmsManager.sendMultipartTextMessage()
方法,使用SmsManager.divideMessage()
方法拆分字符串。
答案 2 :(得分:1)
你可以试试这个:
try {
SmsManager smsManager = SmsManager.getDefault();
ArrayList<String> parts = smsManager.divideMessage(CipherText);
smsManager.sendMultipartTextMessage(phoneNo, null, parts, null, null);
Toast.makeText(getApplicationContext(), "SMS Sent!",
Toast.LENGTH_LONG).show();
} catch (Exception e) {
Toast.makeText(getApplicationContext(),
"SMS faild, please try again later!",
Toast.LENGTH_LONG).show();
e.printStackTrace();
}
如需更多帮助,请参阅this thread