Dialog from service not showing on lollipop when screen is locked

淺唱寂寞╮ 提交于 2019-12-13 01:40:50

问题


I am trying to show a Dialog from service in onStartCommand method

private Dialog incomingCallDialog;

incomingCallDialog = new Dialog(MyService.this, R.style.PopupDialog);
        incomingCallDialog.setCancelable(false);
        incomingCallDialog.requestWindowFeature(Window.FEATURE_NO_TITLE);
        incomingCallDialog.getWindow().setType(WindowManager.LayoutParams.TYPE_SYSTEM_ALERT);
        incomingCallDialog.setContentView(view);

Handler delayHandler = new Handler();
        delayHandler.postDelayed(new Runnable() {
            @Override
            public void run() {                
                    incomingCallDialog.show();               
            }
        }, 100);

This code works fine in SamsungS5 which has Kitkat and when device is locked but it doesn't work on SamsungS6 which has lollipop 5.0.2 when device is locked.

The dialog is not showing at all in Lollipop when device is locked.


回答1:


Change TYPE_SYSTEM_ALERT to TYPE_SYSTEM_OVERLAY it should work



来源:https://stackoverflow.com/questions/29961858/dialog-from-service-not-showing-on-lollipop-when-screen-is-locked

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!