0

can anyone tell me why overlay is not working in the Android pie? Is there any special permission required to do that or something. Because they actually didn't depreciate any functionality like:

WindowManager.LayoutParams.TYPE_APPLICATION_OVERLAY;

is still working and the studio is not giving any error in this code.

stkent
  • 19,772
  • 14
  • 85
  • 111

1 Answers1

0

This is the way i have used to display a dialog overlay on other apps and this is working good in android pie.

 void showDialog() {
    if (context == null)
        context = getApplicationContext();
    LayoutInflater layoutInflater = LayoutInflater.from(context);
    View promptsView = layoutInflater.inflate(R.layout.popup_unlock, null, false);
    Lock9View lock9View = (Lock9View) promptsView.findViewById(R.id.lock_9_view);
    Button forgetPassword = (Button) promptsView.findViewById(R.id.forgetPassword);
    lock9View.setCallBack(new Lock9View.CallBack() {
        @Override
        public void onFinish(String password) {
            if (password.matches(sharedPreference.getPassword(context))) {
                dialog.dismiss();

            } else {
                Toast.makeText(getApplicationContext(), "Wrong Pattern Try Again", Toast.LENGTH_SHORT).show();

            }
        }
    });

    forgetPassword.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            Intent i = new Intent(AppCheckServices.this, PasswordRecoveryActivity.class);
            i.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
            startActivity(i);
            dialog.dismiss();
        }
    });

    dialog = new Dialog(context, android.R.style.Theme_Black_NoTitleBar_Fullscreen);
    dialog.setCanceledOnTouchOutside(false);
    dialog.setCancelable(false);
    dialog.requestWindowFeature(Window.FEATURE_NO_TITLE);

    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
        dialog.getWindow().setType(WindowManager.LayoutParams.TYPE_APPLICATION_OVERLAY);
    } else {
        dialog.getWindow().setType(WindowManager.LayoutParams.TYPE_PHONE);
    }


    dialog.getWindow().setLayout(WindowManager.LayoutParams.MATCH_PARENT, WindowManager.LayoutParams.MATCH_PARENT);
    dialog.setContentView(promptsView);
    dialog.getWindow().setGravity(Gravity.CENTER);

    dialog.setOnKeyListener(new Dialog.OnKeyListener() {
        @Override
        public boolean onKey(DialogInterface dialog, int keyCode,
                             KeyEvent event) {

            if (keyCode == KeyEvent.KEYCODE_BACK
                    && event.getAction() == KeyEvent.ACTION_UP) {
                Intent startMain = new Intent(Intent.ACTION_MAIN);
                startMain.addCategory(Intent.CATEGORY_HOME);
                startMain.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
                startActivity(startMain);
            }
            return true;
        }
    });

    dialog.show();

}
Hussnain Hashmi
  • 203
  • 2
  • 9