Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Android native UPnP service discovery

Tags:

java

android

upnp

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) {
        }
    });
like image 426
Arturs Vancans Avatar asked Sep 02 '13 15:09

Arturs Vancans


People also ask

What is Discovery Service Android?

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.

How do I turn on network discovery on Android?

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 LG P2P service?

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.

What is service discovery protocol explain it?

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.


1 Answers

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!

like image 52
RoundSparrow hilltx Avatar answered Sep 23 '22 07:09

RoundSparrow hilltx