You should measure the voltage levels when the the sensor is covered/uncovered. There are application notes with detailes about the GPIO input voltage conditions. Some STM32 have comparator inputs with adjustable voltage levels.
Some chip families have a COMP peripheral which can compare input voltage to some reference value. Its easier than ADC where you need software for evaluating the measurments. What MCU are you using?
> BTW, can I use GPIO_Analog
GPIO_Analog is meant for two purposes:
connect an internal ADC peripheral for analog voltage measurement.
do not connect to anything internally (saves some power compared to digital input)
it cannot be used for reading digital input value.