Dialog from service not showing on lollipop when s

2019-08-09 04:30发布

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条回答
男人必须洒脱
2楼-- · 2019-08-09 05:29

Change TYPE_SYSTEM_ALERT to TYPE_SYSTEM_OVERLAY it should work

查看更多
登录 后发表回答