通话期间禁用屏幕 [英] Disable screen during call
问题描述
我正在开发一个BB10应用程序,该应用程序需要禁用屏幕,就像在通话过程中将其靠近您的脸一样.我实现了一个接近传感器来检测何时应禁用或启用屏幕,但是BB10的API似乎没有提供打开或关闭屏幕的方法.
I'm working on a BB10 app that needs to disable the screen in the same way that holding it close to your face does during a call. I implemented a proximity sensor to detect when the screen should be disabled or enabled, but BB10's APIs don't seem to provide a way to turn the screen on or off.
我可以用来禁用和重新启用屏幕吗?
What can I use to disable and re-enable the screen?
推荐答案
您可以通过在QML文件中最外面的Container
周围添加Container
并将其background
设置为Color.Black
来解决此问题.然后将id
添加到以前最外面的Container
并实现onScreenEnabled(enabled)
函数以显示或隐藏它.
You can solve this by adding a Container
around the outermost Container
in the QML file, and setting its background
to Color.Black
. Then added an id
to the formerly outermost Container
and implement an onScreenEnabled(enabled)
function to show or hide it.
Container {
background: Color.Black
Container {
id: callContainer
...
}
}
function onScreenEnabled(enabled) {
callContainer.visible = enabled;
}
在.cpp文件中,使用接近传感器的读数发出信号以启用或禁用屏幕:
In the .cpp file, use the proximity sensor's reading to emit a signal to enable or disable the screen:
void CallProgress::checkReading() {
bool isClose = proximitySensor->reading()->close();
this->SetScreenEnabled(!isClose);
}
void CallProgress::SetScreenEnabled(const bool enabled) {
emit screenEnabled(enabled);
}
将信号和函数声明添加到.h文件.在.qml文件中,将发出的信号连接到相应的QML函数.
Add the signal and function declarations to the .h file. In the .qml file, connect the emitted signal to the corresponding QML function.
只要接近传感器的读数检测到用户靠近屏幕,就会隐藏UI.
This will hide the UI whenever the proximity sensor's readings detect that the user is close to the screen.
这篇关于通话期间禁用屏幕的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!