문제

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();
    }
}
도움이 되었습니까?

해결책

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

다른 팁

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.

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top