When close android phone do double tap and send message with mqtt

I have a problem. I want when close android device and double tap to device publish message with mqtt. Is it impossible? If it is not impossible how can i do it?