From Android 4.1 (under Wi-Fi Direct service discovery) it is suppose to support native UPnP service discovery.
I presume it was developed for Wi-Fi Direct, but the methods available seem to be generic. Even the JavaDoc for methods mention that it searches for all UPnP services on the network and not only WiFi Direct slaves/masters.
However, I am failing to implement it so that it works... I manage to set up all requirements and I get positive onSuccess
callbacks, but I receive no onUpnpServiceAvailable
callbacks notifying about services on the network. I do have 3 services on UPnP which I can discover using 3rd-party library.
Has anyone tried this feature?
final Channel mChannel;
final WifiP2pManager mManager;
WifiP2pServiceRequest mRequester;
mManager = (WifiP2pManager) getSystemService(Context.WIFI_P2P_SERVICE);
mChannel = mManager.initialize(this, getMainLooper(), new ChannelListener() {
public void onChannelDisconnected() {
Log.i("CI", "Channel detected!");
}
});
mManager.setUpnpServiceResponseListener(mChannel, new UpnpServiceResponseListener() {
public void onUpnpServiceAvailable(List<String> arg0, WifiP2pDevice arg1) {
Log.i("sd", "Found device!!");
}
});
mRequester = WifiP2pUpnpServiceRequest.newInstance();
mManager.addServiceRequest(mChannel, mRequester, new ActionListener() {
public void onSuccess() {
Log.i("d", "AddServiceRequest success!");
mManager.discoverServices(mChannel, new ActionListener() {
public void onSuccess() {
Log.i("d", "DiscoverServices success!");
}
public void onFailure(int reason) {
}
});
}
public void onFailure(int reason) {
}
});
Network service discovery (NSD) gives your app access to services that other devices provide on a local network. Devices that support NSD include printers, webcams, HTTPS servers, and other mobile devices.
There are two buttons at the top of the home screen: Discover and Options. I tapped Discover and network discovery commenced. The app correctly identified the two devices I have on my network (besides the Android phone), my laptop and my router.
What Is a Peer-to-Peer (P2P) Service? A peer-to-peer (P2P) service is a decentralized platform whereby two individuals interact directly with each other, without intermediation by a third party. Instead, the buyer and the seller transact directly with each other via the P2P service.
The Service Discovery Protocol (SDP) is used by a client device to find out about the services it can use on a server device. An SDP server maintains a database of services; this can be preconfigured (static), or can be built up dynamically as services register with the database system.
Yes, I have tried it, and I think it's all about WIFI_P2P_SERVICE - meaning P2P - meaning PeerToPeer or "Wi-Fi Direct" or "Adhoc Wifi Mode". In other words, it won't work when you are in a normal WiFi situation with an Access Point / station mode.
I don't think Android has any native way to listen for UPnP / SSdP at the OS level except in this situation of "Wi-Fi Direct".
If anyone else wants to chime in, please do!
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With