在发送直接短消息时,没有问题,但是当我发送包含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();
}
}发布于 2015-10-04 19:52:54
你可以试试这个:
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
发布于 2013-12-06 10:27:15
尝试将响应保存在变量中的DNAbaseConvert(plainText)中,并将其传递给sendTextMessage()
String msg=DNAbaseConvert(plainText);
smsManager.sendTextMessage(phoneNo, null, msg, null, null);这是因为来自DNAbaseConvert()的响应可能会在其中造成问题。
发布于 2013-12-07 09:10:39
您可能有一个问题,击中短信的大小限制。如果使用的是SmsManager.sendTextMessage()方法,则可以使用SmsManager.sendMultipartTextMessage()方法和SmsManager.divideMessage()方法来拆分字符串。
https://stackoverflow.com/questions/20421469
复制相似问题