从屏幕检测用户接近程度 [英] Detect user proximity from the screen

查看:119
本文介绍了从屏幕检测用户接近程度的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在开发一个BB10应用程序,该应用程序必须能够禁用屏幕当用户在通话过程中将手机举到脸上时.

I'm working on a BB10 app that needs to be able to disable the screen when the user holds the phone up to his/her face during a call.

我怎么知道用户何时将手机举到脸上?

How can I tell when the user is holding the phone up to his/her face?

推荐答案

要检测用户与手机的距离,可以使用

To detect the user's proximity from the phone, you can use a QProximitySensor.

要使用此功能,您需要将以下几行添加到项目的.pro文件中:

In order to use this, you need to add these lines to your project's .pro file:

CONFIG += mobility
MOBILITY += sensors

在.cpp和.h文件中添加必要的包含:

Add the necessary includes to the .cpp and .h files:

#include <QtSensors/QProximitySensor>
using QtMobility::QProximitySensor;

#include <QtSensors/QProximityReading>
using QtMobility::QProximityReading;

在.h文件中定义接近传感器.在构造函数和析构函数中创建和销毁传感器.

Define the proximity sensor in the .h file. Create and destroy the sensor in your constructor and destructor functions.

通话开始时,将传感器的readingChanged功能连接到要处理的读数,然后将其激活:

When the call starts, connect your sensor's readingChanged function to the one that you intend to handle the reading, and activate it:

connect(proximitySensor, SIGNAL(readingChanged()), this, SLOT(checkReading()));
proximitySensor->setActive(true);

通话结束后,停用传感器:

When the call ends, deactivate the sensor:

proximitySensor->setActive(false);

最后,使用读数的close功能判断设备何时靠近用户的面部.请注意,对于不同的设备,定义为关闭"的距离可能会有所不同.

Finally, use the reading's close function to tell when the device is close to the user's face. Note that the distance defined as "close" may be different for different devices.

bool isClose = proximitySensor->reading()->close();

或者,如果您不想对读数的变化采取行动,则可以跳过连接readingChanged信号并独立使用close功能的方法.

Alternatively, if you don't want to act upon changes to the reading, you can skip connecting the readingChanged signal and use the close function independently.

这篇关于从屏幕检测用户接近程度的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆