0

SMSの送信が必要な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" random text にありますが、別のエミュレーターに送信しようとすると、受信したメッセージが異なります。もっと、ある種のユニコード記号で埋めてください..私の英語でごめんなさい。

4

0 に答える 0