4

SMSを送信するためのモジュールを備えたアプリを作成しています。私は2つのブロードキャストレシーバーと保留中のインテントを使用しています。1つはSMS送信確認用で、もう1つは配信用です。SMS送信ブロードキャストレシーバーは正常に機能していますが、配信が行われていません。

サービスで次のコードを使用しています。

        PendingIntent sentPI = PendingIntent.getBroadcast(this, 0,
                new Intent(SENT), 0);

        PendingIntent deliveredPI = PendingIntent.getBroadcast(this, 0,
                new Intent(DELIVERED), 0);

            //---when the SMS has been sent--- is working alright
            registerReceiver(new BroadcastReceiver()
            {
                public void onReceive(Context arg0, Intent arg1)
                {
                    switch (getResultCode())
                    {
                        case Activity.RESULT_OK:
                            Toast.makeText(getBaseContext(), "SMS sent", 
                                    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;
                    }
                    unregisterReceiver(this);
                }
            }, new IntentFilter(SENT));

            //---when the SMS has been delivered--- this part is not working 
            registerReceiver(new BroadcastReceiver()
            {


                @Override
                public void onReceive(Context arg0, Intent arg1) 
                {
                    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;           

                        default :
                            Toast.makeText(getBaseContext(), "Unable to generate delivery Report", 
                                    Toast.LENGTH_SHORT).show();
                    }
                    unregisterReceiver(this);
                }
            }, new IntentFilter(DELIVERED));        

            SmsManager sms = SmsManager.getDefault();
            sms.sendTextMessage(phoneNumber, null, msg, sentPI, deliveredPI);
4

1 に答える 1

6

ネットワークサービスプロバイダーで送信されるSMSは、配信通知を受け取ることができることを意味します。コードはデバイスで機能しますが、エミュレーターではサービスプロバイダーが含まれていません。そのため、エミュレーターで配信通知が表示されません。

于 2013-08-19T07:44:02.840 に答える