有 Java 编程相关的问题?

你可以在下面搜索框中键入要查询的问题!

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

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


共 (0) 个答案