Unregister a dynamically created receiver
<p>I dynamically register 2 recivers to get the result of sms sent and delivery status in my code, I cannot create a new class and this has to be done in the existing class (which extends dialog).
How do I unregistered the receiver.</p>

<p>I Have read the other posts and they do not help, they either have a separate class or they register the receiver in the xml manifest. </p>

<p>Here is my code</p>

<pre><code>private void sendSMS(String keyword, String msisdn) { 

   String SENT = "SMS_SENT";
   String DELIVERED = "SMS_DELIVERED";

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

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

    mContext.registerReceiver(new BroadcastReceiver(){
        @Override
        public void onReceive(Context arg0, Intent arg1) {
            switch (getResultCode())
            {
                case Activity.RESULT_OK:
                    break;
                case SmsManager.RESULT_ERROR_GENERIC_FAILURE:
                    sendEventLog("Failed(Generic failure)");    
                    break;
                case SmsManager.RESULT_ERROR_NO_SERVICE:
                    sendEventLog("Failed(No service)");     
                    break;
                case SmsManager.RESULT_ERROR_NULL_PDU:
                    sendEventLog("Failed(Null PDU)");   
                    break;
                case SmsManager.RESULT_ERROR_RADIO_OFF:
                    sendEventLog("Failed(Radio off)");  
                    break;
            }
        }
    }, new IntentFilter(SENT));

    //---when the SMS has been delivered---
    mContext.registerReceiver(new BroadcastReceiver(){
        @Override
        public void onReceive(Context arg0, Intent arg1) {
            switch (getResultCode())
            {
                case Activity.RESULT_OK:
                    break;
                case Activity.RESULT_CANCELED:
                    sendEventLog("Failed(SMS not delivered)"); 
                    break;
            }
        }
    }, new IntentFilter(DELIVERED));

   SmsManager MySmsManager = SmsManager.getDefault();
       MySmsManager.sendTextMessage(msisdn, null, keyword, sentPI, deliveredPI);

    }
</code></pre>
