How to get wifi connected device list in alljoyn?

254 views Asked by At

I have use alljoyn for wifi share. I want device list connected to wifi network on channel base.

I have follow one demo but it not call implemented method announced

AboutListener is part of alljoyn.

import org.alljoyn.bus.AboutListener;

public class OnboardingApplication extends Application implements AboutListener {

     @Override
        public void announced(String busName, int version, short port, AboutObjectDescription[] objectDescriptions, Map<String, Variant> aboutMap) {
            Map<String, Object> newMap = new HashMap<String, Object>();
            try {
                newMap = TransportUtil.fromVariantMap(aboutMap);
                String deviceId = (newMap.get(AboutKeys.ABOUT_APP_ID).toString());
                String deviceFriendlyName = (String) newMap.get(AboutKeys.ABOUT_DEVICE_NAME);
                m_logger.debug(TAG, "onAnnouncement received: with parameters: busName:" + busName + ", port:" + port + ", deviceid" + deviceId + ", deviceName:" + deviceFriendlyName);
                addDevice(deviceId, busName, port, deviceFriendlyName, objectDescriptions, newMap);

            } catch (BusException e) {
                e.printStackTrace();
            }
        }

}
2

There are 2 answers

5
LopesFigueiredo On BEST ANSWER

In order to get the announced method called you'll need to register your AboutListener:

org.alljoyn.bus.alljoyn.DaemonInit.PrepareDaemon(getApplicationContext());

//Bus Connection
Status status = mBus.connect();

//Check if connection is established
if (status != Status.OK) {
    return;
}

//Setup Bus Attachment
mBus.useOSLogging(true);
mBus.setDebugLevel("ALLJOYN_JAVA", 7);
mBus.registerAboutListener(mListener);

//Start AboutData Listener
status = mBus.whoImplements(null);

if (status != Status.OK) {
    Log.e(TAG, "whoImplements Error");
} else {
    Log.w(TAG, "whoImplements Success");
}

mListener is your object that implements AboutListener.

When you call whoImplements(null) you are saying you want all announcements from all interfaces.

0
P. Sigurdson On

In addition to what LopesFigueiredo said, try creating your BusAttachment with a remote message policy of Receive. For example:

BusAttachment mBus = new BusAttachment("My Attachment", BusAttachment.RemoteMessage.Receive);