首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >使用SmsManager发送编码的短消息不被接收

使用SmsManager发送编码的短消息不被接收
EN

Stack Overflow用户
提问于 2013-12-06 10:22:36
回答 3查看 631关注 0票数 0

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

纯文本是正常的消息。有什么问题??请帮帮忙。

代码语言:javascript
复制
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();
    }
}
EN

回答 3

Stack Overflow用户

回答已采纳

发布于 2015-10-04 19:52:54

你可以试试这个:

代码语言:javascript
复制
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

票数 1
EN

Stack Overflow用户

发布于 2013-12-06 10:27:15

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

代码语言:javascript
复制
String msg=DNAbaseConvert(plainText);

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

这是因为来自DNAbaseConvert()的响应可能会在其中造成问题。

票数 1
EN

Stack Overflow用户

发布于 2013-12-07 09:10:39

您可能有一个问题,击中短信的大小限制。如果使用的是SmsManager.sendTextMessage()方法,则可以使用SmsManager.sendMultipartTextMessage()方法和SmsManager.divideMessage()方法来拆分字符串。

票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/20421469

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档