да, и тогда я начал получать вышеуказанную ошибку

Dialog из BroadcastReceiver? Это можно сделать? Я работаю над приложением, которое выдает диалоговое окно, если я получаю SMS-сообщение. Я пытаюсь закодировать это в BroadcaseReceiver. Но я не могу использовать эту строку кодаAlertDialog.Builder builder = new AlertDialog.Builder(this);, Может кто-нибудь, пожалуйста, помогите мне с подсказкой!

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

}

Ответы на вопрос(5)

Ваш ответ на вопрос