【问题标题】:How to get wifi connected device list in alljoyn?如何在 alljoyn 中获取 wifi 连接的设备列表?
【发布时间】:2016-12-15 13:32:26
【问题描述】:

我使用 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注册到busAttachment了吗?
  • 是的,我已经注册了
  • @AmitPrajapati 为什么不勾选我的答案?

标签: java android networking wifi alljoyn


【解决方案1】:

为了调用宣布的方法,您需要注册您的 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) 时,你是说你想要来自所有接口的所有公告。

【讨论】:

  • 实际上它并不完美,我需要它,它给我的设备列表总是 0
  • 但是你宣布的方法被调用了吗?
  • 是的,它的电话,但没有找到任何设备列表
  • 每当设备宣布其关于数据时,都会触发宣布的方法,因此通常每个设备都会调用一次。你确定你的智能设备能正确地自我宣布吗?我正在使用Luminaire App 并收到两条通知。
  • 好的,谢谢,我会看到,当我有机会时,如果您有任何示例演示,请提供给我。
【解决方案2】:

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

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

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2022-06-10
    • 2015-08-05
    • 1970-01-01
    • 2011-03-20
    • 2019-05-25
    • 1970-01-01
    • 1970-01-01
    • 2020-07-30
    相关资源
    最近更新 更多