android.view.WindowManager$BadTokenException: Unable to add window android.view.ViewRootImpl$W@c745883 - permission denied

后端 未结 3 1375
遥遥无期
遥遥无期 2021-02-20 00:05

Here\'s my stack trace:

01-30 15:11:41.037 13010-13010/project.app E/AndroidRuntime: FATAL EXCEPTION: main
 Process: project.app, PID: 13010
 android.view.Window         


        
相关标签:
3条回答
  • 2021-02-20 00:25
    TYPE_SYSTEM_ALERT
    

    This constant was deprecated in API level 26. for non-system apps. Use TYPE_APPLICATION_OVERLAY instead.

    0 讨论(0)
  • 2021-02-20 00:30

    Verify SYSTEM_ALERT_WINDOW Permission Or try to provide Overlay Permission Manually.

    As @Fco P. said you can try to change

    mRedBoxDialog.getWindow().setType(WindowManager.LayoutParams.TYPE_SYSTEM_ALERT);

    **## If you are using Lenovo device. Please try with another one. This particular permission makes problem sometime in Lenovo device.****

    0 讨论(0)
  • 2021-02-20 00:32

    I saw this error some time ago, when I updated a native&react app to SDK 26. The problem is the react-native function that creates the red dialog for development. That functions uses TYPE_SYSTEM_ALERT as their type, so you can't use an SDK level bigger than 25 in your hybrid app with that version of react-native, unless you patch that function so it no longer uses TYPE_SYSTEM_ALERT.

    this is the react-native code in 0.48:

    private void showNewError(
          final String message,
          final StackFrame[] stack,
          final int errorCookie,
          final ErrorType errorType) {
        UiThreadUtil.runOnUiThread(
            new Runnable() {
              @Override
              public void run() {
                if (mRedBoxDialog == null) {
                  mRedBoxDialog = new RedBoxDialog(mApplicationContext, DevSupportManagerImpl.this, mRedBoxHandler);
                  mRedBoxDialog.getWindow().setType(WindowManager.LayoutParams.TYPE_SYSTEM_ALERT);
                }
                if (mRedBoxDialog.isShowing()) {
                  // Sometimes errors cause multiple errors to be thrown in JS in quick succession. Only
                  // show the first and most actionable one.
                  return;
                }
                mRedBoxDialog.setExceptionDetails(message, stack);
                updateLastErrorInfo(message, stack, errorCookie, errorType);
                // Only report native errors here. JS errors are reported
                // inside {@link #updateJSError} after source mapping.
                if (mRedBoxHandler != null && errorType == ErrorType.NATIVE) {
                  mRedBoxHandler.handleRedbox(message, stack, RedBoxHandler.ErrorType.NATIVE);
                  mRedBoxDialog.resetReporting(true);
                } else {
                  mRedBoxDialog.resetReporting(false);
                }
                mRedBoxDialog.show();
              }
            });
      } 
    

    You would need to change the mRedBoxDialog.getWindow().setType(WindowManager.LayoutParams.TYPE_SYSTEM_ALERT); call to other type. But, this does not give you any guarantees you'll be able to run your app with SDK 26, when I tried to compile react with SDK 26, other parts of the project "reacted" exploding, so this is unlikely to work at short term (you may need to start fixing other problems). So your options are:

    -Downgrade the app to level 25;

    -Upgrade to react 0.52, where that function no longer exist, and try again (react libraries may not work after this)

    -Patch the function in react-native 0.48 branch and try the patched version. Some other issues related to the SDK may arose (react at this point is still being compiled with SDK 22)

    Happy coding!

    0 讨论(0)
提交回复
热议问题