如何在 alljoyn 中获取 wifi 连接的设备列表?

How to get wifi connected device list in alljoyn?

我已经使用 alljoyn 进行 wifi 共享。我希望设备列表连接到信道基础上的 wifi 网络。

我有一个演示,但它没有调用实现的方法announced

AboutListener 是 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();
            }
        }

}

为了调用已宣布的方法,您需要注册您的 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 是您实现 AboutListener 的对象。

当你调用 whoImplements(null) 时,你是说你想要来自所有接口的所有公告。

除了 LopesFigueiredo 所说的之外,请尝试使用 Receive 的远程消息策略创建 BusAttachment。例如:

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