Yet another question to help me on my DataLayer library (not doing so well am I, lol).
When sending a message over the DataLayer the sendMessage method looks like this
public abstract PendingResult<MessageApi.SendMessageResult> sendMessage (GoogleApiClient client, String nodeId, String path, byte[] data)
And the onMessageReceived callback passes an object containing the same info.
As you can see the last parameter is of type byte[]. I have tried to implement this as follows.
The sendMessage in lib is simple enough:
The onMessageReceived in lib:
and the signature defined in @events
lastly the actual even in B4A:
When I send the message the phone logs the message has sent
The phone logs that a message has been received but then I get an Error
The only thing I can think it is causing this is the handling of a byte[]. I have tried many tweaks to solve but I'm now stuck.
Any ideas?
When sending a message over the DataLayer the sendMessage method looks like this
public abstract PendingResult<MessageApi.SendMessageResult> sendMessage (GoogleApiClient client, String nodeId, String path, byte[] data)
And the onMessageReceived callback passes an object containing the same info.
As you can see the last parameter is of type byte[]. I have tried to implement this as follows.
The sendMessage in lib is simple enough:
B4X:
public void Send(final String NodeID, final long Timeout, final String Path, final byte[] Data) {
new Thread(new Runnable() {
@Override
public void run() {
BA.Log("Sending message to " + NodeID);
mGoogleApiClient.blockingConnect(Timeout, TimeUnit.MILLISECONDS);
Wearable.MessageApi.sendMessage(mGoogleApiClient, NodeID, Path, Data);
}
}).start();
}
The onMessageReceived in lib:
B4X:
@Hide
@Override
public void onMessageReceived(MessageEvent msg) {
lastMessageReceivedNodeId = msg.getSourceNodeId();
BA.Log("Dynamic Message Received");
if (mBA.subExists(mEventname + "_messagereceived")) {
BA.Log("MessageReceived Sub present");
mBA.raiseEvent(mGoogleApiClient, mEventname + "_messagereceived", new Object[] {msg.getSourceNodeId(), msg.getPath(), msg.getRequestId(), msg.getData()});
}
}
and the signature defined in @events
B4X:
MessageReceived(SourceNodeID As String, RequestID As Int, Path As String, Data() As Byte)
lastly the actual even in B4A:
B4X:
Sub DataLayer_MessageReceived(SourceNodeID As String, RequestID As Int, Path As String, Data() As Byte)
ToastMessageShow(Path, False)
Log(SourceNodeID)
Log(Path)
End Sub
When I send the message the phone logs the message has sent
The phone logs that a message has been received but then I get an Error
java.lang.Exception: Sub datalayer_messagereceived signature does not match expected signature.
The only thing I can think it is causing this is the handling of a byte[]. I have tried many tweaks to solve but I'm now stuck.
Any ideas?
Last edited: