android.view.WindowManager $ BadTokenException:无法添加窗口android.view.ViewRootImpl$W@c745883-权限被拒绝 [英] android.view.WindowManager$BadTokenException: Unable to add window android.view.ViewRootImpl$W@c745883 - permission denied

查看:1520
本文介绍了android.view.WindowManager $ BadTokenException:无法添加窗口android.view.ViewRootImpl$W@c745883-权限被拒绝的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这是我的堆栈跟踪:

01-30 15:11:41.037 13010-13010/project.app E/AndroidRuntime: FATAL EXCEPTION: main
 Process: project.app, PID: 13010
 android.view.WindowManager$BadTokenException:
   Unable to add window android.view.ViewRootImpl$W@c745883 -- permission denied for window type 2003
   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 com.facebook.react.devsupport.DevSupportManagerImpl$4.run(DevSupportManagerImpl.java:344)
   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)

我找到了关于TYPE_SYSTEM_ERROR在Android Oreo(8)中已被弃用的答案,因此我实现了以下同样发现的方法:

I found an answer about TYPE_SYSTEM_ERROR being deprecated in Android Oreo (8) so I implemented the following method that I also found:

public void fixAndroid() {
    WindowManager.LayoutParams params;
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
      params = new WindowManager.LayoutParams(
              WindowManager.LayoutParams.MATCH_PARENT,
              WindowManager.LayoutParams.MATCH_PARENT,
              WindowManager.LayoutParams.TYPE_APPLICATION_OVERLAY,
              WindowManager.LayoutParams.FLAG_FULLSCREEN,
              PixelFormat.TRANSLUCENT);
    } else {
      params = new WindowManager.LayoutParams(
              WindowManager.LayoutParams.MATCH_PARENT,
              WindowManager.LayoutParams.MATCH_PARENT,
              WindowManager.LayoutParams.TYPE_SYSTEM_ERROR,
              WindowManager.LayoutParams.FLAG_FULLSCREEN,
              PixelFormat.TRANSLUCENT);
    }
  }

在我的onCreate()方法中,我拥有:

Inside of my onCreate() method I have:

  @Override
  public void onCreate (Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    // Checking permissions on init
    fixAndroid();
  }

我仍然会收到错误消息.

I still get the error.

我正在使用Expo SDK 21,React Native 0.48.该应用程序已分离到ExpoKit.

I am using Expo SDK 21, React Native 0.48. The application has been detached to ExpoKit.

每次更改后,我都会清理项目,然后通过Android Studio在模拟器上运行它.

After each change I clean my project and then run it on an Emulator through Android Studio.

我正在Nexus 5X模拟器上运行此程序,并在API 27上运行.

I am running this on a Nexus 5X emulator, running on API 27.

推荐答案

TYPE_SYSTEM_ALERT

对于非系统应用,此常量在API级别26中已弃用.使用TYPE_APPLICATION_OVERLAY代替.

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

这篇关于android.view.WindowManager $ BadTokenException:无法添加窗口android.view.ViewRootImpl$W@c745883-权限被拒绝的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆