Android: WifiP2pManager.discoverServices has no UPNP data

I am working on an application that uses UPNP to open TV Set Top Box via UPNP in order to put pictures taken on the device on the TV.

In onCreate

I get the manager and initialize the channel.

protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    mManager = (WifiP2pManager) getSystemService(Context.WIFI_P2P_SERVICE);
    mChannel = mManager.initialize(this, getMainLooper(), null);
    mReceiver = new WiFiDirectBroadcastReceiver(mManager, mChannel);
    mIntentFilter = new IntentFilter();
    mIntentFilter.addAction(WifiP2pManager.WIFI_P2P_STATE_CHANGED_ACTION);
    mIntentFilter.addAction(WifiP2pManager.WIFI_P2P_PEERS_CHANGED_ACTION);
    mIntentFilter.addAction(WifiP2pManager.WIFI_P2P_CONNECTION_CHANGED_ACTION);
    mIntentFilter.addAction(WifiP2pManager.WIFI_P2P_THIS_DEVICE_CHANGED_ACTION);

    mManager.setUpnpServiceResponseListener(mChannel, new WifiP2pManager.UpnpServiceResponseListener() {
        @Override
        public void onUpnpServiceAvailable(List<String> uniqueServiceNames, WifiP2pDevice srcDevice) {
            UpnpServices service = new UpnpServices(uniqueServiceNames, srcDevice);
            mPeers.add(service);
        }
    });
}

      

In onPause

I am calling my subroutine setServiceListeners

:

private void setServiceListeners()
{
    mManager.addServiceRequest(mChannel, WifiP2pServiceRequest.newInstance(WifiP2pServiceInfo.SERVICE_TYPE_UPNP), mRequestListener);
    mManager.discoverServices(mChannel, mActionListener);
}

      

Everything seems to succeed in LogCat but UpnpServiceResponseListener

never gets called and when I try to sniff the network I see no UPNP traffic - no IGMP connection, no SSDP, nothing.

Is there a step here? From everything I've seen (including http://developer.android.com/guide/topics/connectivity/wifip2p.html among others) I am doing what I have to.

TIA for any help you can give to figure this out.

+3


source to share


1 answer


As you know, UPnP services belong to the UPnP device. So you need to get the instance first WifiP2pDevice

and connect / join to it.



See http://developer.android.com/reference/android/net/wifi/p2p/WifiP2pManager.html#connect(android.net.wifi.p2p.WifiP2pManager.Channel , android.net.wifi.p2p.WifiP2pConfig. android.net.wifi.p2p.WifiP2pManager.ActionListener)

0


source







All Articles