【问题标题】:Sending Encoded SMS using SmsManager does not get received未收到使用 SmsManager 发送编码短信
【发布时间】:2015-10-05 03:52:54
【问题描述】:

在发送直接短信时没有问题,但是当我发送包含DNA bases(A , G , T , C only) 的可操作SMS 时,它就不起作用了。

明文是普通消息。有什么问题??请帮忙。

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

【问题讨论】:

  • @Mike M "返回的字符串长度只有 7-10" 是的,我只使用 smsManager.sendTextMessage(phoneNo, null, DNAbaseConvert(plainText), null, null);
  • 谢谢@Mike M,它现在可以工作了。 ArrayList 部分 = sms.divideMessage(CipherText); sms.sendMultipartTextMessage(phoneNo, null, parts, null, null);
  • @Mike M,好的,没问题。

标签: android sms smsmanager


【解决方案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

【讨论】:

    【解决方案2】:

    尝试将来自DNAbaseConvert(plainText) 的响应保存在一个变量中并将其传递给sendTextMessage()

    String msg=DNAbaseConvert(plainText);
    
    smsManager.sendTextMessage(phoneNo, null, msg, null, null);
    

    这是因为来自 DNAbaseConvert() 的响应可能会导致其内部出现问题..

    【讨论】:

    • sam 569:我将它存储在变量中并使用 Toast 消息显示它。返回值没问题。但短信没有发送。
    【解决方案3】:

    您可能在达到 SMS 消息大小限制时遇到问题。如果您使用SmsManager.sendTextMessage() 方法,则可以尝试使用SmsManager.sendMultipartTextMessage() 方法,并使用SmsManager.divideMessage() 方法来拆分您的字符串。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2015-04-29
      • 2015-02-05
      • 1970-01-01
      • 2011-10-30
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多