Detailed explanation of Android programming based on distance sensor to control the extinction of mobile phone screen

This paper describes the method of Android programming to control the extinction of mobile phone screen based on distance sensor. Share with you for your reference, as follows:

In real life, when you make a phone call, the mobile phone is next to your head, and the screen will go out. This is to prevent your head from pressing any mobile phone key~

This function can be realized by using distance sensor

The P-Sensor distance sensor can sense the distance between the mobile phone and the human body. The specific purpose is to open the P-Sensor during the call, so when the mobile phone screen is close to the user's face, it will automatically sense the distance between the mobile phone and the human body. When it is less than a certain value, it will turn off the screen and no longer receive the user's touch screen event, so as to effectively prevent the occurrence of false touch event during the call.

The specific implementation code is as follows:

Think about it carefully. Do you need the power supply of your mobile phone when the screen is off~

Therefore, you need to add permissions:

I won't post the renderings. I need a real machine test

In addition, for Android permission control, click here to view the detailed description

Attachment: click here to download the complete example code.

More readers interested in Android related content can view the special topics of this site: introduction and advanced tutorial of Android development, summary of Android view skills, summary of activity operation skills of Android programming, summary of Android operation skills of SQLite database, summary of Android operation skills of JSON format data, summary of Android resource operation skills, and Android control usage summary

I hope this article will help you in Android programming.

The content of this article comes from the network collection of netizens. It is used as a learning reference. The copyright belongs to the original author.
THE END
分享
二维码
< <上一篇
下一篇>>