Aayush Rana
Aayush Rana

Reputation: 1303

Android SMS Delivery Broadcast receiver is not working in emulator

I m creating an app which has module for sending sms. I m using 2 broadcast receiver and Pending intents , one for the sms sent acknowledgement and another for the is delivery .. the sms sent broadcast reciever is working fine but the delivery is not coming.

I m using the following code in a service.

        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);

Upvotes: 4

Views: 2826

Answers (1)

Ram
Ram

Reputation: 2530

The sms sent on Network service provider means,you can get the delivery notification.The code works on the device,but in emulator it not contain any service provider.That's way it not shows delivery notification on emulator.

Upvotes: 6

Related Questions