AlertDialog desde BroadcastReceiver ?? Se puede hacer?

AlertDialog desde BroadcastReceiver? Se puede hacer? Estoy trabajando en una aplicación que mostrará un cuadro de diálogo si recibo un mensaje SMS. Estoy tratando de codificar esto dentro de un BroadcaseReceiver. Pero no puedo usar esta línea de códigoAlertDialog.Builder builder = new AlertDialog.Builder(this);. ¿Puede alguien ayudarme con una pista?

public class SMSPopUpReceiver extends BroadcastReceiver {

    private static final String LOG_TAG = "SMSReceiver";
    public static final int NOTIFICATION_ID_RECEIVED = 0x1221;
    static final String ACTION = "android.provider.Telephony.SMS_RECEIVED";

    public void onReceive(Context context, Intent intent) {
        Log.i(LOG_TAG, "onReceive");

        if (intent.getAction().equals(SMSPopUpReceiver.ACTION)) {
            StringBuilder sb = new StringBuilder();
            Bundle bundle = intent.getExtras();
            if (bundle != null) {
            Object[] pdus = (Object[]) bundle.get("pdus");

            for (Object pdu : pdus){
                    SmsMessage messages =
            SmsMessage.createFromPdu((byte[]) pdu);

            sb.append("Received SMS\nFrom: ");
            sb.append(messages.getDisplayOriginatingAddress());
            sb.append("\n----Message----\n");
            sb.append( messages.getDisplayMessageBody());
            }
            }
            Log.i(SMSPopUpReceiver.LOG_TAG,
            "[SMSApp] onReceiveIntent: " + sb);
            Toast.makeText
            (context, sb.toString(), Toast.LENGTH_LONG).show();
            }

        AlertDialog.Builder builder = new AlertDialog.Builder(this);
        builder.setMessage("Are you sure you want to exit?")
               .setCancelable(false)
               .setPositiveButton("Yes", new DialogInterface.OnClickListener() {
                   public void onClick(DialogInterface dialog, int id) {
                       dialog.cancel();
                   }
               })
               .setNegativeButton("No", new DialogInterface.OnClickListener() {
                   public void onClick(DialogInterface dialog, int id) {
                        dialog.cancel();
                   }
               });
        AlertDialog alert = builder.create();
    }

}

Respuestas a la pregunta(5)

Su respuesta a la pregunta