Android-在后台应用程序时启动对话框



我有一个有调用对话框的应用程序。我正在尝试在锁定屏幕上显示呼叫对话框。当应用程序不在后台时,它已经工作,实际上当应用程序打开并且锁定屏幕处于活动状态时它不起作用。
这是我的代码:

    public class CustomMainActivity extends QtActivity implements SensorEventListener
    {
    @Override
    protected void onStart() {
        super.onStart();
        if (getCallId() != 0)
            getWindow().addFlags(WindowManager.LayoutParams.FLAG_TURN_SCREEN_ON |
                WindowManager.LayoutParams.FLAG_SHOW_WHEN_LOCKED |
                WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON |
                WindowManager.LayoutParams.FLAG_DISMISS_KEYGUARD);
        else
            getWindow().clearFlags(WindowManager.LayoutParams.FLAG_TURN_SCREEN_ON |
            WindowManager.LayoutParams.FLAG_SHOW_WHEN_LOCKED |
            WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON |
            WindowManager.LayoutParams.FLAG_DISMISS_KEYGUARD);
    .
    .
    .
    }
    @Override
    protected void onResume() {
        super.onResume();
        if (getCallId() != 0)
            getWindow().addFlags(WindowManager.LayoutParams.FLAG_TURN_SCREEN_ON |
                WindowManager.LayoutParams.FLAG_SHOW_WHEN_LOCKED |
                WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON |
                WindowManager.LayoutParams.FLAG_DISMISS_KEYGUARD);
        else
            getWindow().clearFlags(WindowManager.LayoutParams.FLAG_TURN_SCREEN_ON |
            WindowManager.LayoutParams.FLAG_SHOW_WHEN_LOCKED |
            WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON |
            WindowManager.LayoutParams.FLAG_DISMISS_KEYGUARD);
    .
    .
    .
    }
}

尝试在 onCreate() 中添加这些标志。

@Override
protected void onCreate(Bundle savedInstanceState) {
    // TODO Auto-generated method stub
    getWindow().addFlags(
            WindowManager.LayoutParams.FLAG_SHOW_WHEN_LOCKED
                    | WindowManager.LayoutParams.FLAG_TURN_SCREEN_ON
                    | WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON);
    super.onCreate(savedInstanceState);
}

相关内容

  • 没有找到相关文章

最新更新