0

I am inflating view using window manager for lock.But I want to display dialog on it when it display wrong lock many times.Dialog is display under layout inflated by window manager in background.I can't find much about it.

My code for display dialog is:

    pDialog = new SweetAlertDialog(context, SweetAlertDialog.WARNING_TYPE)
            .setTitleText("Internet Error !")
            .setContentText("Do you want to enable internet?")
            .setCancelText("No,Cancel plz!")
            .setConfirmText("Yes,Enable it")
            .showCancelButton(true)
            .setCancelClickListener(
                    new SweetAlertDialog.OnSweetClickListener() {
                        @Override
                        public void onClick(SweetAlertDialog sDialog) {
                            sDialog.setTitleText("Cancelled!")
                                    .setContentText(
                                            "You Can't Enable Internet")
                                    .setConfirmText("OK")
                                    .showCancelButton(false)
                                    .setCancelClickListener(null)
                                    .setConfirmClickListener(null)
                                    .changeAlertType(
                                            SweetAlertDialog.ERROR_TYPE);

                        }
                    })
            .setConfirmClickListener(
                    new SweetAlertDialog.OnSweetClickListener() {

                        @Override
                        public void onClick(
                                SweetAlertDialog sweetAlertDialog) {

                            Intent intent = new Intent();
                            intent.setAction(Settings.ACTION_DATA_ROAMING_SETTINGS);
                            context.startActivity(intent);
                            sweetAlertDialog.dismiss();

                        }
                    });
    pDialog.getWindow().setType(
            WindowManager.LayoutParams.TYPE_SYSTEM_ALERT);
    pDialog.show();

for layout inflate in window manager:

    this.context = context;
    if (intent.getAction().equals(Intent.ACTION_SCREEN_OFF)) {

        Log.d("tagKrishna", "come in if");
    } else {
        Log.d("tagKrishna", "come in else");
        numLockView = View.inflate(context, R.layout.activity_receiver,
                null);
        numLockView2 = View.inflate(context,
                R.layout.activity_unclock_photo_lock_screen, null);
        numLockView3 = View.inflate(context,
                R.layout.unlock_pin_lock_screen, null);

        numLockView4 = View
                .inflate(context, R.layout.forget_passcode, null);

        bindView();
        // params = new WindowManager.LayoutParams(
        // WindowManager.LayoutParams.MATCH_PARENT,
        // WindowManager.LayoutParams.MATCH_PARENT,
        // 2003 ,
        // 262184, PixelFormat.TRANSLUCENT);
        params = new WindowManager.LayoutParams(
                WindowManager.LayoutParams.MATCH_PARENT,
                WindowManager.LayoutParams.MATCH_PARENT,
                WindowManager.LayoutParams.TYPE_SYSTEM_ERROR,
                WindowManager.LayoutParams.FLAG_DISMISS_KEYGUARD 
                        | WindowManager.LayoutParams.FLAG_WATCH_OUTSIDE_TOUCH
                        | WindowManager.LayoutParams.FLAG_LAYOUT_NO_LIMITS
                        | WindowManager.LayoutParams.FLAG_LAYOUT_IN_SCREEN,
                PixelFormat.TRANSLUCENT);
        windowManager = (WindowManager) context.getSystemService("window");
        windowManager.addView(numLockView, params);

        init();
        addListener();

    }
Krishna Kachhela
  • 773
  • 1
  • 7
  • 24

1 Answers1

0
AlertDialog.Builder builder = new AlertDialog.Builder(context);
builder.setMessage("Write your message here.");
builder.setCancelable(true);

builder.setPositiveButton(
    "Yes",
    new DialogInterface.OnClickListener() {
        public void onClick(DialogInterface dialog, int id) {
            dialog.cancel();
        }
    });

builder.setNegativeButton(
    "No",
    new DialogInterface.OnClickListener() {
        public void onClick(DialogInterface dialog, int id) {
            dialog.cancel();
        }
    });

AlertDialog alert = builder.create();
alert.show();
  • No it will not work in on lock. If you want to show dialog under lock then you should use Service to show dialog. Please check this http://stackoverflow.com/questions/19074466/android-how-to-show-dialog-or-activity-over-lock-screen-not-unlock-the-screen – Md Mobinur Rahman May 08 '17 at 12:23