API Overlay Resolution Error 26

When my application tries to draw a system overlap, it resets and tells me that the permission was denied for the type of window 2010. However, I demand that the user provide ACTION_MANAGE_OVERLAY_PERMISSIONtraining activities during the first installation. Also, this only happens on API 26. I tested all the other supported SDKs and I can draw the overlay without crashes or errors.

I used

Settings.canDrawOverlay(context);

and it returns true. Thus, it seems that the system knows that permission has been granted, but the problem is not resolved.

Here is the overlay code:

    LayoutInflater inflater = (LayoutInflater) mContext.getSystemService(LAYOUT_INFLATER_SERVICE);
    inflater.inflate(R.layout.view_driving, mRelativeLayout);

    WindowManager.LayoutParams layoutParams = new WindowManager.LayoutParams(
            WindowManager.LayoutParams.MATCH_PARENT,
            WindowManager.LayoutParams.MATCH_PARENT,
            WindowManager.LayoutParams.TYPE_SYSTEM_ERROR,
            WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE | WindowManager.LayoutParams.FLAG_LAYOUT_NO_LIMITS,
            PixelFormat.TRANSLUCENT);

    if(Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP){
        layoutParams.flags = WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS;
    } else{
        layoutParams.flags = WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS;
    }

    if(Build.VERSION.SDK_INT >= Build.VERSION_CODES.O){
        layoutParams.flags = WindowManager.LayoutParams.TYPE_APPLICATION_OVERLAY;
    }

    int uiOptions = View.SYSTEM_UI_FLAG_LAYOUT_STABLE
            | View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION
            | View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN
            | View.SYSTEM_UI_FLAG_HIDE_NAVIGATION // hide nav bar
            | View.SYSTEM_UI_FLAG_FULLSCREEN // hide status bar
            | View.SYSTEM_UI_FLAG_IMMERSIVE_STICKY;

    layoutParams.screenOrientation = ActivityInfo.SCREEN_ORIENTATION_PORTRAIT;

    mRelativeLayout.setSystemUiVisibility(uiOptions);

    if(Settings.canDrawOverlays(mContext)){
        WindowManager windowManager = (WindowManager) mContext.getSystemService(WINDOW_SERVICE);
        windowManager.addView(mRelativeLayout, layoutParams);  
    }

A crash occurs when addView is called.

permission denied 2010

+4
source share

Source: https://habr.com/ru/post/1686241/


All Articles