3

I'm working on an app that uses UPNP to discover a TV Set Top Box via UPNP in order to put pictures taken on the device up 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 call my setServiceListeners routine:

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

Everything appears to be successful in the LogCat but the UpnpServiceResponseListener is never called and when I try to sniff the network I don't see any UPNP traffic - no IGMP join, no SSDP, nothing.

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

TIA for any help you can give figuring this out.

Dan S
  • 31
  • 1

1 Answers1

0

As you know, UPnP Services belongs to UPnP Device. So you need to get WifiP2pDevice instance first and connect/join with 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)

yjzhang
  • 4,859
  • 3
  • 19
  • 21