Is there a way i can do that ?
In short: Yes. But it will take some good effort to integrate the necessary components.
The key problem is that you need to listen for ICMP network packets. Such functionality is not accessible from Java and would require either JNI code or an external program. (To my knowledge, it also requires a rooted device.)
You will need a library or program that can process network traffic, such as Jpcap (which would require some modification to work on Android). You could also install and run an instance of
View original answer
tcpdump in the background and parse its output.