Disable screen during call

2019-08-06 01:47发布

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?

1条回答
混吃等死
2楼-- · 2019-08-06 02:26

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;
}

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);
}

Add the signal and function declarations to the .h file. In the .qml file, connect the emitted signal to the corresponding QML function.

This will hide the UI whenever the proximity sensor's readings detect that the user is close to the screen.

查看更多
登录 后发表回答