我有一个有调用对话框的应用程序。我正试图在锁定屏幕上显示呼叫对话框。它在应用程序不在后台时工作,实际上当应用程序打开并且锁定屏幕处于活动状态时它不起作用。
这是我的代码:
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);
.
.
.
}
}
答案 0 :(得分:0)
尝试在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);
}