窗口管理$ BadTokenException无法添加窗口 [英] WindowManager$BadTokenException unable to add window

查看:362
本文介绍了窗口管理$ BadTokenException无法添加窗口的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我开发的应用程序对于后台录像,这就是为什么我使用的窗口管理器,但它并没有工作了以下错误me.gives:

  15 08-23:38:21.021:E / AndroidRuntime(4200):了java.lang.RuntimeException:无法创建服务com.example.prankapp.BackgroundVideoRecorder:android.view。窗口管理$ BadTokenException:无法添加窗口android.view.ViewRootImpl$W@418c0b68  - 拒绝使用此窗口类型权限
    08-23 15:38:21.021:E / AndroidRuntime(4200):在android.app.ActivityThread.handleCreateService(ActivityThread.java:2277)
    08-23 15:38:21.021:E / AndroidRuntime(4200):在android.app.ActivityThread.access $ 1600(ActivityThread.java:128)
    08-23 15:38:21.021:E / AndroidRuntime(4200):在android.app.ActivityThread $ H.handleMessage(ActivityThread.java:1215)
    08-23 15:38:21.021:E / AndroidRuntime(4200):在android.os.Handler.dispatchMessage(Handler.java:99)
    08-23 15:38:21.021:E / AndroidRuntime(4200):在android.os.Looper.loop(Looper.java:137)
    08-23 15:38:21.021:E / AndroidRuntime(4200):在android.app.ActivityThread.main(ActivityThread.java:4517)
    08-23 15:38:21.021:E / AndroidRuntime(4200):在java.lang.reflect.Method.invokeNative(本机方法)
    08-23 15:38:21.021:E / AndroidRuntime(4200):在java.lang.reflect.Method.invoke(Method.java:511)
    08-23 15:38:21.021:E / AndroidRuntime(4200):在com.android.internal.os.ZygoteInit $ MethodAndArgsCaller.run(ZygoteInit.java:993)
    08-23 15:38:21.021:E / AndroidRuntime(4200):在com.android.internal.os.ZygoteInit.main(ZygoteInit.java:760)
    08-23 15:38:21.021:E / AndroidRuntime(4200):在dalvik.system.NativeStart.main(本机方法)
    08-23 15:38:21.021:E / AndroidRuntime(4200):android.view.WindowManager $ BadTokenException:产生的原因无法添加窗口android.view.ViewRootImpl$W@418c0b68 - 拒绝使用此窗口类型权限
    08-23 15:38:21.021:E / AndroidRuntime(4200):在android.view.ViewRootImpl.setView(ViewRootImpl.java:707)
    08-23 15:38:21.021:E / AndroidRuntime(4200):在android.view.WindowManagerImpl.addView(WindowManagerImpl.java:301)
    08-23 15:38:21.021:E / AndroidRuntime(4200):在android.view.WindowManagerImpl.addView(WindowManagerImpl.java:215)
    08-23 15:38:21.021:E / AndroidRuntime(4200):在android.view.WindowManagerImpl $ CompatModeWrapper.addView(WindowManagerImpl.java:140)
    08-23 15:38:21.021:E / AndroidRuntime(4200):在com.example.prankapp.BackgroundVideoRecorder.onCreate(BackgroundVideoRecorder.java:53)
    08-23 15:38:21.021:E / AndroidRuntime(4200):在android.app.ActivityThread.handleCreateService(ActivityThread.java:2267)
    08-23 15:38:21.021:E / AndroidRuntime(4200):10 ...更多

我的窗口管理器,code:

 窗口管理=(窗口管理器)this.getSystemService(BackgroundVideoRecorder.WINDOW_SERVICE);
            surfaceView =新SurfaceView(本);
            的LayoutParams的LayoutParams =新WindowManager.LayoutParams(
                1,1,
                WindowManager.LayoutParams.TYPE_SYSTEM_OVERLAY,
                WindowManager.LayoutParams.FLAG_WATCH_OUTSIDE_TOUCH,
                PixelFormat.TRANSLUCENT
            );
            //layoutParams.gravity = Gravity.LEFT | Gravity.TOP;
            windowManager.addView(surfaceView,的LayoutParams);
            。surfaceView.getHolder()的addCallback(本);

请帮忙me.Thanks提前。


解决方案

  15 08-23:38:21.021:E / AndroidRuntime(4200):因:android.view.WindowManager $ BadTokenException:无法添加窗口android.view.ViewRootImpl$W@418c0b68  - 拒绝使用此窗口类型权限

问题:
 在maifest文件权限丢失。

解决方案:
使用下面的权限 AndroidManifest

  android.permission.SYSTEM_ALERT_WINDOW

I am developing app for background videorecording ,thats why i used WindowManager,but it did not worked for me.gives following errors:

08-23 15:38:21.021: E/AndroidRuntime(4200): java.lang.RuntimeException: Unable to create service com.example.prankapp.BackgroundVideoRecorder: android.view.WindowManager$BadTokenException: Unable to add window android.view.ViewRootImpl$W@418c0b68 -- permission denied for this window type
    08-23 15:38:21.021: E/AndroidRuntime(4200):     at android.app.ActivityThread.handleCreateService(ActivityThread.java:2277)
    08-23 15:38:21.021: E/AndroidRuntime(4200):     at android.app.ActivityThread.access$1600(ActivityThread.java:128)
    08-23 15:38:21.021: E/AndroidRuntime(4200):     at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1215)
    08-23 15:38:21.021: E/AndroidRuntime(4200):     at android.os.Handler.dispatchMessage(Handler.java:99)
    08-23 15:38:21.021: E/AndroidRuntime(4200):     at android.os.Looper.loop(Looper.java:137)
    08-23 15:38:21.021: E/AndroidRuntime(4200):     at android.app.ActivityThread.main(ActivityThread.java:4517)
    08-23 15:38:21.021: E/AndroidRuntime(4200):     at java.lang.reflect.Method.invokeNative(Native Method)
    08-23 15:38:21.021: E/AndroidRuntime(4200):     at java.lang.reflect.Method.invoke(Method.java:511)
    08-23 15:38:21.021: E/AndroidRuntime(4200):     at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:993)
    08-23 15:38:21.021: E/AndroidRuntime(4200):     at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:760)
    08-23 15:38:21.021: E/AndroidRuntime(4200):     at dalvik.system.NativeStart.main(Native Method)
    08-23 15:38:21.021: E/AndroidRuntime(4200): Caused by: android.view.WindowManager$BadTokenException: Unable to add window android.view.ViewRootImpl$W@418c0b68 -- permission denied for this window type
    08-23 15:38:21.021: E/AndroidRuntime(4200):     at android.view.ViewRootImpl.setView(ViewRootImpl.java:707)
    08-23 15:38:21.021: E/AndroidRuntime(4200):     at android.view.WindowManagerImpl.addView(WindowManagerImpl.java:301)
    08-23 15:38:21.021: E/AndroidRuntime(4200):     at android.view.WindowManagerImpl.addView(WindowManagerImpl.java:215)
    08-23 15:38:21.021: E/AndroidRuntime(4200):     at android.view.WindowManagerImpl$CompatModeWrapper.addView(WindowManagerImpl.java:140)
    08-23 15:38:21.021: E/AndroidRuntime(4200):     at com.example.prankapp.BackgroundVideoRecorder.onCreate(BackgroundVideoRecorder.java:53)
    08-23 15:38:21.021: E/AndroidRuntime(4200):     at android.app.ActivityThread.handleCreateService(ActivityThread.java:2267)
    08-23 15:38:21.021: E/AndroidRuntime(4200):     ... 10 more

My windowManager code:

windowManager = (WindowManager) this.getSystemService(BackgroundVideoRecorder.WINDOW_SERVICE);
            surfaceView = new SurfaceView(this);
            LayoutParams layoutParams = new WindowManager.LayoutParams(
                1, 1,
                WindowManager.LayoutParams.TYPE_SYSTEM_OVERLAY,
                WindowManager.LayoutParams.FLAG_WATCH_OUTSIDE_TOUCH,
                PixelFormat.TRANSLUCENT
            );
            //layoutParams.gravity = Gravity.LEFT | Gravity.TOP;
            windowManager.addView(surfaceView, layoutParams);
            surfaceView.getHolder().addCallback(this);

Please help me.Thanks in advance.

解决方案

08-23 15:38:21.021: E/AndroidRuntime(4200): Caused by: android.view.WindowManager$BadTokenException: Unable to add window android.view.ViewRootImpl$W@418c0b68 -- permission denied for this window type

Problem: Permission missing in maifest file.

Solution: Use following permission in AndroidManifest.

android.permission.SYSTEM_ALERT_WINDOW

这篇关于窗口管理$ BadTokenException无法添加窗口的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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