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.