Note 2 doesn't have magnetic sensor. All cover use proximity sensor.
but i had a strange problem..
i was testing the software provided in the OP with a normal flip cover..
its working well when we place our hand or something near to the proximity sensor in good light.
but not in the dark....