我已将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)时,是说您希望从所有接口发出所有公告。

关于java - 如何在alljoyn中获得wifi连接的设备列表?,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/41165449/

10-13 07:23