1

See:

if (Build.VERSION.SDK_INT >= 27) {
    dialog.getWindow().setType(WindowManager.LayoutParams.TYPE_APPLICATION_OVERLAY);
} else {
    dialog.getWindow().setType(WindowManager.LayoutParams.TYPE_TOAST);
}

Above code is not crashing my app, but there is no effect for my Oreo 27 8.0.1 version.

See method in my Non-Activity class:

private void showAlertDialog(final Context context) {
    DialogInterface.OnClickListener listener = new DialogInterface.OnClickListener() {
        @Override
        public void onClick(DialogInterface dialog, int which) {
            Toast.makeText(context, "test", Toast.LENGTH_SHORT).show();
        }
    };

    LayoutInflater inflater = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);

    AlertDialog.Builder builder = new AlertDialog.Builder(context)
        .setCancelable(false)
        .setPositiveButton("OK", listener);

    View view = inflater
        .inflate(R.layout.row_passcode_dialog, null);
    builder.setView(view);

    Dialog dialog = builder.create();

    if (Build.VERSION.SDK_INT >= 27) {
        dialog.getWindow().setType(WindowManager.LayoutParams.TYPE_APPLICATION_OVERLAY);
    } else {
        dialog.getWindow().setType(WindowManager.LayoutParams.TYPE_TOAST);
    }

    dialog.show();

}

Also check: Permission error is still showing even when added permission in manifest

Pochmurnik
  • 780
  • 6
  • 18
  • 35
Pooja Singh
  • 121
  • 6
  • What error it says in logcat? – Piyush Feb 22 '19 at 12:32
  • @Piyush No error, but no effect, not showing dialog box – Pooja Singh Feb 22 '19 at 12:36
  • @PoojaSingh did you check it >https://stackoverflow.com/questions/46208897/android-permission-denied-for-window-type-2038-using-type-application-overlay – Adil Feb 22 '19 at 12:37
  • @AD10 Hi, I already differentiate the version, problem is TYPE.TOAST is working fine till Nougat, and TYPE OVERLAY is not giving effect/working on Oreo. – Pooja Singh Feb 22 '19 at 12:44
  • okay it means there is permission problem, you need to fire intent for it like this >>https://stackoverflow.com/questions/40437721/how-to-give-screen-overlay-permission-on-my-activity – Adil Feb 22 '19 at 12:49
  • check the answer of @Ahmad Shahwaiz – Adil Feb 22 '19 at 12:50
  • If the app targets API level 23 or higher, the app user must explicitly grant this permission to the app through a permission management screen. The app requests the user's approval by sending an intent with action ACTION_MANAGE_OVERLAY_PERMISSION. The app can check whether it has this authorization by calling Settings.canDrawOverlays() – Adil Feb 22 '19 at 12:51

0 Answers0