美文网首页React Native
Android 8.0 & Dialog & permissio

Android 8.0 & Dialog & permissio

作者: 南窗云 | 来源:发表于2018-07-19 11:22 被阅读0次

    Android 8.0 Dialog 需要适配,否则会报错闪退:

     android.view.WindowManager$BadTokenException: Unable to add window android.view.ViewRootImpl$W@e283326 -- permission denied for window type 2003
            at android.view.ViewRootImpl.setView(ViewRootImpl.java:905)
            at android.view.WindowManagerGlobal.addView(WindowManagerGlobal.java:372)
            at android.view.WindowManagerImpl.addView(WindowManagerImpl.java:128)
            at android.app.Dialog.show(Dialog.java:454)
            at com.maple.recorder.player.PlayDialog.showDialog(PlayDialog.java:141)
            at com.maple.recorder.player.PlayDialog.showDialog(PlayDialog.java:136)
            at com.maple.recordwav.ui.PlayPage.dialogPlay(PlayPage.java:123)
            at com.maple.recordwav.ui.PlayPage.access$200(PlayPage.java:37)
            at com.maple.recordwav.ui.PlayPage$2.onItemClick(PlayPage.java:92)
            at android.widget.AdapterView.performItemClick(AdapterView.java:321)
            at android.widget.AbsListView.performItemClick(AbsListView.java:1217)
            at android.widget.AbsListView$PerformClick.run(AbsListView.java:3203)
    

    解决方案:

    将Type类型

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

    改为如下,即可

    getWindow().setType(WindowManager.LayoutParams.TYPE_APPLICATION_OVERLAY);
    

    参考文章

    《android 8.0使用悬浮窗时,报错permission denied for window type 2007》

    相关文章

      网友评论

        本文标题:Android 8.0 & Dialog & permissio

        本文链接:https://www.haomeiwen.com/subject/bgozpftx.html