我使用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();
}
}
}
答案 0 :(得分: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)时,你说你想要所有接口的所有公告。
答案 1 :(得分:0)
除了LopesFigueiredo所说的内容之外,尝试使用Receive的远程消息策略创建BusAttachment。例如:
BusAttachment mBus = new BusAttachment("My Attachment", BusAttachment.RemoteMessage.Receive);