Android发送不同于消息的短信字符串

时间:2013-01-11 12:46:06

标签: java android string sms send

嘿我正在创建需要发送短信的android项目 继承我的代码:

private void sendSMS(String destSMS, String msgSMS) {
    // TODO Auto-generated method stub
    String SENT = "SMS_SENT";
    String DELIVERED = "SMS_DELIVERED";

    PendingIntent pi = PendingIntent.getBroadcast(this, 0,
            new Intent(SENT), 0);
    PendingIntent deliveri_pi = PendingIntent.getBroadcast(this, 0,
            new Intent(DELIVERED), 0);

    BroadcastReceiver brSend = new BroadcastReceiver() {
        @Override
        public void onReceive(Context context, Intent intent) {
            // TODO Auto-generated method stub
            switch (getResultCode()) {
            case Activity.RESULT_OK:
                Toast.makeText(getBaseContext(), "SMS Delivered",
                        Toast.LENGTH_SHORT).show();
                break;
            case SmsManager.RESULT_ERROR_GENERIC_FAILURE:
                Toast.makeText(getBaseContext(), "Generic Failure",
                        Toast.LENGTH_SHORT).show();
                break;
            case SmsManager.RESULT_ERROR_NO_SERVICE:
                Toast.makeText(getBaseContext(), "No Service",
                        Toast.LENGTH_SHORT).show();
                break;
            case SmsManager.RESULT_ERROR_NULL_PDU:
                Toast.makeText(getBaseContext(), "Null PDU",
                        Toast.LENGTH_SHORT).show();
                break;
            case SmsManager.RESULT_ERROR_RADIO_OFF:
                Toast.makeText(getBaseContext(), "Radio Off",
                        Toast.LENGTH_SHORT).show();
                break;
            }
        }
    };
    BroadcastReceiver brDelivered = new BroadcastReceiver() {

        @Override
        public void onReceive(Context context, Intent intent) {
            // TODO Auto-generated method stub
            switch (getResultCode()) {
            case Activity.RESULT_OK:
                Toast.makeText(getBaseContext(), "SMS delivered",
                        Toast.LENGTH_SHORT).show();
                break;
            case Activity.RESULT_CANCELED:
                Toast.makeText(getBaseContext(), "SMS not delivered",
                        Toast.LENGTH_SHORT).show();
                break;
            }
        }
    };
    registerReceiver(brSend, new IntentFilter(SENT));
    registerReceiver(brDelivered, new IntentFilter(DELIVERED));

    SmsManager smsman = SmsManager.getDefault();
    smsman.sendTextMessage(destSMS, null, msgSMS, pi, deliveri_pi);
}

btnSend.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View v) {
            // TODO Auto-generated method stub
            String dest, messageEnc;
            dest = etDest.getText().toString();
            messageEnc = etCipher.getText().toString();
            try {
                sendSMS(dest, messageEnc);
            } catch (Exception e) {
                Toast.makeText(getBaseContext(),
                        "Gagal karena " + e.toString(), Toast.LENGTH_SHORT)
                        .show();
                // TODO Auto-generated catch block
                e.printStackTrace();
            }
        }
    });

问题是在textfield text is ='th!Azasd“随机文本,但是当我试图发送到另一个模拟器时收到的消息不同,消息接收就像”@hu @@@“完全不同,消息接收长度更多,并填充一些unicode符号.. 对不起我的英文。

0 个答案:

没有答案