Scan nearby Wifi P2P services

So, I want to make an app that will start a Wifi P2P service and scan nearby available Wifi P2P services. This is how I will create Wifi P2P service.

But how do I scan nearby P2P services? There are 2 ways that claim to scan this and this. I don't understand the difference between two. I did try watching youtube videos but they were repeating the same thing. Pls, tell me which one to use to scan nearby P2P services created by other phones.