无法添加窗口android.view.ViewRootImpl$W@53e1e83-窗口类型2038的权限被拒绝

时间:2019-12-01 09:54:10

标签: java android

添加TYPE_APPLICATION_OVERLAY并在OREO中运行时出现错误,如果我在kitkat中运行完美但在oreo崩溃中运行,该如何解决我的错误...

添加TYPE_APPLICATION_OVERLAY并在OREO中运行时出现错误,如果我在kitkat中运行完美但在oreo崩溃中运行,该如何解决我的错误...

当我添加TYPE_APPLICATION_OVERLAY并在OREO中运行时出现错误,如果我在kitkat中完美运行但在oreo崩溃中运行,该如何解决我的错误... 请帮助

此代码

private static class OverlayDialog extends AlertDialog {

    public OverlayDialog(Activity activity) {
        super(activity, R.style.OverlayDialog);
        WindowManager.LayoutParams params = getWindow().getAttributes();
        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
            params.type = WindowManager.LayoutParams.TYPE_APPLICATION_OVERLAY;
        }
        else
        {
            params.type = WindowManager.LayoutParams.TYPE_SYSTEM_ERROR;
        }
        params.dimAmount = 0.0F; // transparent
        params.width = 0;
        params.height = 0;
        params.gravity = Gravity.BOTTOM;
        getWindow().setAttributes(params);
        getWindow().setFlags(FLAG_SHOW_WHEN_LOCKED | FLAG_NOT_TOUCH_MODAL, 0xffffff);
        setOwnerActivity(activity);
        setCancelable(false);
    }

    public final boolean dispatchTouchEvent(MotionEvent motionevent) {
        return true;
    }

    protected final void onCreate(Bundle bundle) {
        super.onCreate(bundle);
        FrameLayout framelayout = new FrameLayout(getContext());
        framelayout.setBackgroundColor(0);
        setContentView(framelayout);
    }
}

此错误

     Process: io.github.homelocker.app, PID: 4470
android.view.WindowManager$BadTokenException: Unable to add window android.view.ViewRootImpl$W@a0e9804 -- permission denied for window type 2038
    at android.view.ViewRootImpl.setView(ViewRootImpl.java:789)
    at android.view.WindowManagerGlobal.addView(WindowManagerGlobal.java:356)
    at android.view.WindowManagerImpl.addView(WindowManagerImpl.java:93)
    at android.app.Dialog.show(Dialog.java:330)
    at io.github.homelocker.lib.HomeKeyLocker.lock(HomeKeyLocker.java:28)
    at io.github.homelocker.app.MainActivity.onCheckedChanged(MainActivity.java:51)
    at android.widget.CompoundButton.setChecked(CompoundButton.java:171)
    at android.widget.ToggleButton.setChecked(ToggleButton.java:71)
    at android.widget.CompoundButton.toggle(CompoundButton.java:127)
    at android.widget.CompoundButton.performClick(CompoundButton.java:132)
    at android.view.View$PerformClick.run(View.java:24770)
    at android.os.Handler.handleCallback(Handler.java:790)
    at android.os.Handler.dispatchMessage(Handler.java:99)
    at android.os.Looper.loop(Looper.java:164)
    at android.app.ActivityThread.main(ActivityThread.java:6494)
    at java.lang.reflect.Method.invoke(Native Method)
    at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:438)
    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:807)

请帮助...

0 个答案:

没有答案