How do you use the broadcast warning dialog box in android?

So, I have a broadcast receiver that listens for incoming SMS and searches for SMS for certain conditions. I implemented the receiver in the manifest and in a separate class from my activity.

* EDIT: * Depending on whether the SMS contains a specific term, I need to open a dialog box, and in this dialog box the user will be given the opportunity to go to a specific website or not to go to a specific website.

If I did this in another language, I would just have a global variable that the recipient would change, and then another method would check its value to determine if it needs to do something, but I can’t do this in android .

+2
android sms broadcastreceiver
May 30 '11 at 3:41
source share
4 answers

I'm not sure your title and your question are the same, but if you want to open the website in a browser, just run Intent from your BroadcastReceiver.

If you want an explicit AlertDialog, then see AlertDialog from BroadcastReceiver ?? Can this be done? for some details: you will need to use the intent and start the Activity with the new task flag set.

EDIT: you would do something like this:

public void onReceive(Context context, Intent intent) { Intent i = new Intent(context, {CLASSNAME}.class); i.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); context.startActivity(i); } 
+2
May 30 '11 at 3:48 a.m.
source share

If they allow this, any application can lock the screen and can create problems for other applications. That is why I think that Android did not give us leverage to use the Alert window for the broadcaster. Maybe I'm wrong, but I checked it once, and it didn’t work.

Alternative you can use TOAST

+1
Dec 19 2018-11-11T00: 00Z
source share

You want the warning dialog box to appear, which opens on top of everything. Use the intention to start a new activity with a fully transparent / see through background. This method makes the alert dialog box appear as it is on top of the desktop with icons in the background; -)

0
Jul 6 2018-11-11T00:
source share

, if you want to open the warning dialog after receiving a response in onRecieve, and then add the following code to OnRecieve, here I am warning the dialog after clicking the notification.

 Intent intent = new Intent(mainContext,HomeActivity.class).putExtra("fromNotificationClick",true); PendingIntent pIntent = PendingIntent.getActivity(mainContext, (int) System.currentTimeMillis(), intent, 0); 

, then in your home life add the following code to onCreate,

 boolean fromNotificationClick=false; Bundle extras=getIntent().getExtras(); if(null!=extras) fromNotificationClick=extras.getBoolean("fromNotificationClick"); if(fromNotificationClick){ alert(); } 

Finally, add the code for the alert method.

 public void alert() { new AlertDialog.Builder(HomeActivity.this).setIcon(R.drawable.help).setTitle("Alert") .setMessage("Are you sure....") .setPositiveButton("Yes", new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { Toast.makeText(getBaseContext(), "Coming to help", Toast.LENGTH_SHORT).show(); } }).setNegativeButton("No", new DialogInterface.OnClickListener(){ @Override public void onClick(DialogInterface dialog, int which) { Toast.makeText(getBaseContext(), "NO...", Toast.LENGTH_SHORT).show(); } }).show(); } 
0
May 23 '17 at 7:33
source share



All Articles