还要保证窗口可以悬浮于其他应用,判断代码如下: if (!Settings.canDrawOverlays(this)) { Int._permission den">
当前位置:   article > 正文

【Android开发】解决permission denied for window type 2038

permission denied for window type 2038

在Android 8.0以后对于悬浮窗有了很大的限制,当你想要将视图View加入到WindowManager时,除了在Manifest文件中声明该权限以外:

    <uses-permission android:name="android.permission.SYSTEM_ALERT_WINDOW" />

 还要保证窗口可以悬浮于其他应用,判断代码如下:

  1. if (!Settings.canDrawOverlays(this)) {
  2. Intent intent = new Intent();
  3. intent.setAction(Settings.ACTION_MANAGE_OVERLAY_PERMISSION);
  4. startActivity(intent);
  5. }

找到当前应用,手动授予权限,返回,OK,大功告成。


 

  1. int type = Build.VERSION.SDK_INT >= Build.VERSION_CODES.O ?
  2. WindowManager.LayoutParams.TYPE_APPLICATION_OVERLAY :
  3. WindowManager.LayoutParams.TYPE_PHONE;
  4. WindowManager mWm = (WindowManager) getSystemService(Context.WINDOW_SERVICE);
  5. WindowManager.LayoutParams params = new WindowManager.LayoutParams(
  6. WindowManager.LayoutParams.WRAP_CONTENT,
  7. WindowManager.LayoutParams.WRAP_CONTENT,
  8. type,
  9. WindowManager.LayoutParams.FLAG_NOT_TOUCH_MODAL
  10. | WindowManager.LayoutParams.FLAG_LAYOUT_NO_LIMITS
  11. | WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE
  12. | WindowManager.LayoutParams.FLAG_NOT_TOUCHABLE
  13. | WindowManager.LayoutParams.FLAG_HARDWARE_ACCELERATED,
  14. PixelFormat.TRANSLUCENT);
  15. params.format = PixelFormat.RGBA_8888;
  16. params.gravity = Gravity.TOP | Gravity.CENTER_VERTICAL;

 

声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/笔触狂放9/article/detail/198057?site
推荐阅读
相关标签
  

闽ICP备14008679号