我正在尝试在Android上使用AllJoyn进行设备发现工作。在示例应用程序之后,我能够获得findAdvertisedName的回调并能够加入会话。但是当调用proxyBusObject上的任何方法时,它会消除BusBlocked异常。尽管使用SignalEmitter,BusSignals仍能正常工作。
mBus = new BusAttachment(context.getPackageName(), BusAttachment.RemoteMessage.Receive);
mBus.enableConcurrentCallbacks();
status = mBus.connect();
if (Status.OK != status) {
return;
} else {
busAttachmentState = BusAttachmentState.CONNECTED;
}
mBus.registerBusListener(new BusListener() {
@Override
public void foundAdvertisedName(String name,
short transport,
String namePrefix) {
mBus.enableConcurrentCallbacks();
short contactPort = CONTACT_PORT;
SessionOpts sessionOpts = new SessionOpts();
sessionOpts.traffic = SessionOpts.TRAFFIC_MESSAGES;
sessionOpts.isMultipoint = false;
sessionOpts.proximity = SessionOpts.PROXIMITY_ANY;
sessionOpts.transports = SessionOpts.TRANSPORT_ANY;
Mutable.IntegerValue sessionId = new Mutable.IntegerValue();
Status status = mBus.joinSession(name,
contactPort,
sessionId,
sessionOpts,
new SessionListener());
mProxyObj = mBus.getProxyBusObject("com.my.well.known.name",
"/MyService",
sessionId.value,
new Class[] { SampleInterface.class });
mSampleInterface = mProxyObj.getInterface(SampleInterface.class);
mSampleInterface.Test(); // BusMethod call throws exception every time
});
我也试过在一个单独的线程上调用busMethod但是得到了同样的错误。有谁知道这里可能出现什么问题?
更新:编辑代码以添加BusAttachment创建代码段。