by Grawmpy Troll
Checks first to see if the phone is in portrait mode (so it won't try to turn off the screen if you're gaming in landscape mode). It uses the proximity sensor to see if you have placed the phone in an area where the proximity between itself and any item is between 0-1 cm. If it is, it turns off the screen, saves the current volume levels, and sets all sounds to 0%. When you remove the phone from something close-by and the proximity is more than 0-1 cm, the screen is turned back on and the volume level is reset to the previous level.
v2 ➡ Fixed instability and portrait mode mandatory setting. This version should be much more compatible with most phones.