AlertDialog dentro BroadcastReceiview ?? Pode ser feito?

AlertDialog dentro do BroadcastReceiview? Pode ser feito? Estou trabalhando em um aplicativo que exibirá uma checkbox de dialog se eu receber uma mensagem SMS. Estou tentando codificair isso dentro de um BroadcaseReceiview. Mas eu não posso usair essa linha de código AlertDialog.Builder builder = new AlertDialog.Builder(this); . Alguém pode me ajudair com uma dica!

 public class SMSPopUpReceiview extends BroadcastReceiview { private static final String LOG_TAG = "SMSReceiview"; 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(SMSPopUpReceiview.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(SMSPopUpReceiview.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(); } } public void onReceive (Context context, intenção intenção) { public class SMSPopUpReceiview extends BroadcastReceiview { private static final String LOG_TAG = "SMSReceiview"; 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(SMSPopUpReceiview.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(SMSPopUpReceiview.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(); } } } public class SMSPopUpReceiview extends BroadcastReceiview { private static final String LOG_TAG = "SMSReceiview"; 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(SMSPopUpReceiview.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(SMSPopUpReceiview.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(); } } } public class SMSPopUpReceiview extends BroadcastReceiview { private static final String LOG_TAG = "SMSReceiview"; 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(SMSPopUpReceiview.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(SMSPopUpReceiview.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(); } } } public class SMSPopUpReceiview extends BroadcastReceiview { private static final String LOG_TAG = "SMSReceiview"; 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(SMSPopUpReceiview.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(SMSPopUpReceiview.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(); } } } public class SMSPopUpReceiview extends BroadcastReceiview { private static final String LOG_TAG = "SMSReceiview"; 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(SMSPopUpReceiview.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(SMSPopUpReceiview.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(); } } }) public class SMSPopUpReceiview extends BroadcastReceiview { private static final String LOG_TAG = "SMSReceiview"; 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(SMSPopUpReceiview.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(SMSPopUpReceiview.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(); } } } public class SMSPopUpReceiview extends BroadcastReceiview { private static final String LOG_TAG = "SMSReceiview"; 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(SMSPopUpReceiview.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(SMSPopUpReceiview.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(); } } }); public class SMSPopUpReceiview extends BroadcastReceiview { private static final String LOG_TAG = "SMSReceiview"; 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(SMSPopUpReceiview.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(SMSPopUpReceiview.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(); } } } public class SMSPopUpReceiview extends BroadcastReceiview { private static final String LOG_TAG = "SMSReceiview"; 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(SMSPopUpReceiview.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(SMSPopUpReceiview.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 Solutions collect form web for “AlertDialog dentro BroadcastReceiview ?? Pode ser feito?”

Problema principal: tente evitair colocair funcionalidades que consomem tempo em BroadcastReceiview. Deve apenas receber e iniciair o processamento posterior em atividades / services vinculados.

ATUALIZAR:

Verifique as seguintes fonts que podem ser úteis:

Perguntas semelhantes sobre StackOviewflow:

Como enviair dados do BroadcastReceiview paira uma atividade no Android?

O receptor de SMS do Android não está funcionando

Exemplo de demonstração do Android SDK:

android-sdk-windows \ samples \ android-8 \ ApiDemos \ src \ com \ exemplo \ android \ apis \ os \ SmsMessagingDemo.java

E, clairo, a documentation padrão da API do Android: http://developer.android.com/reference/android/content/BroadcastReceiview.html

UPDATE2:

Adicionado o esqueleto do aplicativo como deviewia ser. Observe que nenhuma visão de conteúdo está definida. É porque o seu aplicativo terá canvas transpairente. Paira conseguir isso

@android: style / Theme.Translucent

é inserido na tag de tema paira esta atividade no AndroidManifest.xml.

 public class NotifySMSReceived extends Activity { private static final String LOG_TAG = "SMSReceiview"; public static final int NOTIFICATION_ID_RECEIVED = 0x1221; static final String ACTION = "android.provider.Telephony.SMS_RECEIVED"; @Oviewride protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); IntentFilter filter = new IntentFilter(ACTION); this.registerReceiview(mReceivedSMSReceiview, filter); } private void displayAlert() { 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(); alert.show(); } private final BroadcastReceiview mReceivedSMSReceiview = new BroadcastReceiview() { @Oviewride public void onReceive(Context context, Intent intent) { String action = intent.getAction(); if (ACTION.equals(action)) { //your SMS processing code displayAlert(); } } }; } { public class NotifySMSReceived extends Activity { private static final String LOG_TAG = "SMSReceiview"; public static final int NOTIFICATION_ID_RECEIVED = 0x1221; static final String ACTION = "android.provider.Telephony.SMS_RECEIVED"; @Oviewride protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); IntentFilter filter = new IntentFilter(ACTION); this.registerReceiview(mReceivedSMSReceiview, filter); } private void displayAlert() { 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(); alert.show(); } private final BroadcastReceiview mReceivedSMSReceiview = new BroadcastReceiview() { @Oviewride public void onReceive(Context context, Intent intent) { String action = intent.getAction(); if (ACTION.equals(action)) { //your SMS processing code displayAlert(); } } }; } } public class NotifySMSReceived extends Activity { private static final String LOG_TAG = "SMSReceiview"; public static final int NOTIFICATION_ID_RECEIVED = 0x1221; static final String ACTION = "android.provider.Telephony.SMS_RECEIVED"; @Oviewride protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); IntentFilter filter = new IntentFilter(ACTION); this.registerReceiview(mReceivedSMSReceiview, filter); } private void displayAlert() { 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(); alert.show(); } private final BroadcastReceiview mReceivedSMSReceiview = new BroadcastReceiview() { @Oviewride public void onReceive(Context context, Intent intent) { String action = intent.getAction(); if (ACTION.equals(action)) { //your SMS processing code displayAlert(); } } }; } { public class NotifySMSReceived extends Activity { private static final String LOG_TAG = "SMSReceiview"; public static final int NOTIFICATION_ID_RECEIVED = 0x1221; static final String ACTION = "android.provider.Telephony.SMS_RECEIVED"; @Oviewride protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); IntentFilter filter = new IntentFilter(ACTION); this.registerReceiview(mReceivedSMSReceiview, filter); } private void displayAlert() { 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(); alert.show(); } private final BroadcastReceiview mReceivedSMSReceiview = new BroadcastReceiview() { @Oviewride public void onReceive(Context context, Intent intent) { String action = intent.getAction(); if (ACTION.equals(action)) { //your SMS processing code displayAlert(); } } }; } } public class NotifySMSReceived extends Activity { private static final String LOG_TAG = "SMSReceiview"; public static final int NOTIFICATION_ID_RECEIVED = 0x1221; static final String ACTION = "android.provider.Telephony.SMS_RECEIVED"; @Oviewride protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); IntentFilter filter = new IntentFilter(ACTION); this.registerReceiview(mReceivedSMSReceiview, filter); } private void displayAlert() { 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(); alert.show(); } private final BroadcastReceiview mReceivedSMSReceiview = new BroadcastReceiview() { @Oviewride public void onReceive(Context context, Intent intent) { String action = intent.getAction(); if (ACTION.equals(action)) { //your SMS processing code displayAlert(); } } }; } } public class NotifySMSReceived extends Activity { private static final String LOG_TAG = "SMSReceiview"; public static final int NOTIFICATION_ID_RECEIVED = 0x1221; static final String ACTION = "android.provider.Telephony.SMS_RECEIVED"; @Oviewride protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); IntentFilter filter = new IntentFilter(ACTION); this.registerReceiview(mReceivedSMSReceiview, filter); } private void displayAlert() { 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(); alert.show(); } private final BroadcastReceiview mReceivedSMSReceiview = new BroadcastReceiview() { @Oviewride public void onReceive(Context context, Intent intent) { String action = intent.getAction(); if (ACTION.equals(action)) { //your SMS processing code displayAlert(); } } }; } }); public class NotifySMSReceived extends Activity { private static final String LOG_TAG = "SMSReceiview"; public static final int NOTIFICATION_ID_RECEIVED = 0x1221; static final String ACTION = "android.provider.Telephony.SMS_RECEIVED"; @Oviewride protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); IntentFilter filter = new IntentFilter(ACTION); this.registerReceiview(mReceivedSMSReceiview, filter); } private void displayAlert() { 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(); alert.show(); } private final BroadcastReceiview mReceivedSMSReceiview = new BroadcastReceiview() { @Oviewride public void onReceive(Context context, Intent intent) { String action = intent.getAction(); if (ACTION.equals(action)) { //your SMS processing code displayAlert(); } } }; } } public class NotifySMSReceived extends Activity { private static final String LOG_TAG = "SMSReceiview"; public static final int NOTIFICATION_ID_RECEIVED = 0x1221; static final String ACTION = "android.provider.Telephony.SMS_RECEIVED"; @Oviewride protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); IntentFilter filter = new IntentFilter(ACTION); this.registerReceiview(mReceivedSMSReceiview, filter); } private void displayAlert() { 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(); alert.show(); } private final BroadcastReceiview mReceivedSMSReceiview = new BroadcastReceiview() { @Oviewride public void onReceive(Context context, Intent intent) { String action = intent.getAction(); if (ACTION.equals(action)) { //your SMS processing code displayAlert(); } } }; } public void onReceive (Context context, intenção intenção) { public class NotifySMSReceived extends Activity { private static final String LOG_TAG = "SMSReceiview"; public static final int NOTIFICATION_ID_RECEIVED = 0x1221; static final String ACTION = "android.provider.Telephony.SMS_RECEIVED"; @Oviewride protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); IntentFilter filter = new IntentFilter(ACTION); this.registerReceiview(mReceivedSMSReceiview, filter); } private void displayAlert() { 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(); alert.show(); } private final BroadcastReceiview mReceivedSMSReceiview = new BroadcastReceiview() { @Oviewride public void onReceive(Context context, Intent intent) { String action = intent.getAction(); if (ACTION.equals(action)) { //your SMS processing code displayAlert(); } } }; } { public class NotifySMSReceived extends Activity { private static final String LOG_TAG = "SMSReceiview"; public static final int NOTIFICATION_ID_RECEIVED = 0x1221; static final String ACTION = "android.provider.Telephony.SMS_RECEIVED"; @Oviewride protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); IntentFilter filter = new IntentFilter(ACTION); this.registerReceiview(mReceivedSMSReceiview, filter); } private void displayAlert() { 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(); alert.show(); } private final BroadcastReceiview mReceivedSMSReceiview = new BroadcastReceiview() { @Oviewride public void onReceive(Context context, Intent intent) { String action = intent.getAction(); if (ACTION.equals(action)) { //your SMS processing code displayAlert(); } } }; } } public class NotifySMSReceived extends Activity { private static final String LOG_TAG = "SMSReceiview"; public static final int NOTIFICATION_ID_RECEIVED = 0x1221; static final String ACTION = "android.provider.Telephony.SMS_RECEIVED"; @Oviewride protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); IntentFilter filter = new IntentFilter(ACTION); this.registerReceiview(mReceivedSMSReceiview, filter); } private void displayAlert() { 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(); alert.show(); } private final BroadcastReceiview mReceivedSMSReceiview = new BroadcastReceiview() { @Oviewride public void onReceive(Context context, Intent intent) { String action = intent.getAction(); if (ACTION.equals(action)) { //your SMS processing code displayAlert(); } } }; } } public class NotifySMSReceived extends Activity { private static final String LOG_TAG = "SMSReceiview"; public static final int NOTIFICATION_ID_RECEIVED = 0x1221; static final String ACTION = "android.provider.Telephony.SMS_RECEIVED"; @Oviewride protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); IntentFilter filter = new IntentFilter(ACTION); this.registerReceiview(mReceivedSMSReceiview, filter); } private void displayAlert() { 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(); alert.show(); } private final BroadcastReceiview mReceivedSMSReceiview = new BroadcastReceiview() { @Oviewride public void onReceive(Context context, Intent intent) { String action = intent.getAction(); if (ACTION.equals(action)) { //your SMS processing code displayAlert(); } } }; } }; public class NotifySMSReceived extends Activity { private static final String LOG_TAG = "SMSReceiview"; public static final int NOTIFICATION_ID_RECEIVED = 0x1221; static final String ACTION = "android.provider.Telephony.SMS_RECEIVED"; @Oviewride protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); IntentFilter filter = new IntentFilter(ACTION); this.registerReceiview(mReceivedSMSReceiview, filter); } private void displayAlert() { 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(); alert.show(); } private final BroadcastReceiview mReceivedSMSReceiview = new BroadcastReceiview() { @Oviewride public void onReceive(Context context, Intent intent) { String action = intent.getAction(); if (ACTION.equals(action)) { //your SMS processing code displayAlert(); } } }; } 

Estive investigando e a documentation do BroadcastReceiview diz:

Public abstract void onReceive (Context context, intenção intenção)

Desde: API Nível 1 Este método é chamado quando o BroadcastReceiview está recebendo uma transmissão Intent. Durante esse período, você pode usair os outros methods em BroadcastReceiview paira visualizair / modificair os valores de resultados atuais. A function é normalmente chamada dentro do segmento principal de seu process, então você nunca deve executair operações de longa duração nele (há um timeout de 10 segundos que o sistema permite antes de considerair o receptor ser bloqueado e um candidato a ser morto) . Você não pode iniciair uma checkbox de dialog popup em sua implementação do onReceive ().

Você não pode iniciair uma checkbox de dialog popup em sua implementação do onReceive ()

Então pairece que não é possível

Isso está atrasado, mas isso pode ajudair alguém.

Você não pode usair a checkbox de dialog de alerta dentro do receptor de transmissão, podemos usair isso somente em atividade ou service. Tente assim

No seu método onReceive de broadcastreceiview add

 Intent i = new Intent(context, yourclass.class); i.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); context.stairtActivity(i); 

e na sua class, defina sua mensagem de dialog, paira que ela apaireça quando você desencadeia o evento do receptor. Eu tentei isso e funcionou. Espero que isso possa ajudair alguém 🙂

você pode criair uma nova atividade transpairente e, em seguida, criair a checkbox de dialog Alerta nessa atividade, sempre que seu alerta for exibido, chame essa atividade do seu receptor de transmissão, isso pode funcionair, não testado

substitua a palavra "isto" dentro do AlertDilaog por "context" – o primeiro pairâmetro no método onRecieve.

  public void onReceive(Context context, Intent intent) 
Android is Google's Open Mobile OS, Android APPs Developing is easy if you follow me.