简体   繁体   中英

Sending Encoded SMS using SmsManager does not get received

When in send direct SMS there is no problem but when I send operational SMS that contains DNA bases(A , G , T , C only) then it is not working.

Plaintext is normal message. Whats the problem?? Please help.

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();
    }
}

Try saving the response from DNAbaseConvert(plainText) in a variable and pass it to sendTextMessage()

String msg=DNAbaseConvert(plainText);

smsManager.sendTextMessage(phoneNo, null, msg, null, null);

This is because the response from DNAbaseConvert() may caused problem inside it..

You might be having a problem hitting the SMS message size limit. If you're using the SmsManager.sendTextMessage() method, you might instead try the SmsManager.sendMultipartTextMessage() method, with the SmsManager.divideMessage() method to split up your string.

You can try this:

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();
      }

For more help you can see this thread

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM