0

Up to Android 7 my Incoming call locker app working well, and i hide incoming call dialog but in Android 8 incoming call dialog always shown in above Activity.

       int LAYOUT_FLAG;
        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
            LAYOUT_FLAG = WindowManager.LayoutParams.TYPE_APPLICATION_OVERLAY;
        } else {
            LAYOUT_FLAG = WindowManager.LayoutParams.TYPE_SYSTEM_ERROR;
        }
        WindowManager.LayoutParams params = new WindowManager.LayoutParams(WindowManager.LayoutParams.MATCH_PARENT,
                WindowManager.LayoutParams.MATCH_PARENT, LAYOUT_FLAG, 263464,
                WindowManager.LayoutParams.WRAP_CONTENT);

        mPrefs = PreferenceManager.getDefaultSharedPreferences(this);
        winMangr = (WindowManager) getApplicationContext().getSystemService(Context.WINDOW_SERVICE);
        getWindow().setAttributes(params);
        wraprView = new RelativeLayout(getBaseContext());
        View.inflate(this, mLayout, wraprView);
        winMangr.addView(wraprView, params);

Here some screenshot

Android 7

App on Android 7.0

Android 8

enter image description here

Attaullah
  • 3,856
  • 3
  • 48
  • 63

1 Answers1

0

You can register a window focus change event then send android.intent.action.CLOSE_SYSTEM_DIALOGS broadcast to close all system dialogs.

@Override
public void onWindowFocusChanged(boolean hasFocus) {
        super.onWindowFocusChanged(hasFocus);

        if (! hasFocus) {
            Intent closeDialog = new Intent(Intent.ACTION_CLOSE_SYSTEM_DIALOGS);
            sendBroadcast(closeDialog);
        }
}

But please note that doing so will force dismiss ALL system dialogs (including Power Off/Restart dialog) which prevent users from turning off the phone while your app is running.

nhoxbypass
  • 9,695
  • 11
  • 48
  • 71