1

I want to show system level alert dialog in background service, I found How to display a Dialog from a Service but this answer use

dialog.getWindow().setType(WindowManager.LayoutParams.TYPE_SYSTEM_ALERT);

and I could not find it in Xamarin AlertDialog API.

What can I do now?

Did I miss any things?

Dharman
  • 30,962
  • 25
  • 85
  • 135
sorosh_sabz
  • 2,356
  • 2
  • 32
  • 53

1 Answers1

3

Try this:

    Android.App.AlertDialog.Builder alert = new Android.App.AlertDialog.Builder(this);
    alert.SetTitle("Confirm delete");
    alert.SetMessage("Lorem ipsum dolor sit amet, consectetuer adipiscing elit.");
    alert.SetPositiveButton("OK", (senderAlert, args) => {
        Toast.MakeText(this, "Ok button Tapped!", ToastLength.Short).Show();
    });

    Dialog dialog = alert.Create();
    dialog.Window.SetType(Android.Views.WindowManagerTypes.SystemAlert);
    dialog.Show();
wishmaster
  • 1,303
  • 8
  • 15
  • What if from simple class needs to show system alert where you can not use context 'this'. How will you create system alert? – Ishwor Khanal Dec 16 '17 at 01:53