i made a project, where i established a successfull communication from my bluetooth plugin to my javascript. From my Javascript i register a callback to my plugin that way in java:
if (action.equals(ACTION_REGISTER_CALLBACK)) {
if(mJSCallback != null) {
pluginResult = new PluginResult(PluginResult.Status.ERROR, "An event callback has already been registered.");
} else {
mJSCallback = callbackId;
pluginResult = new PluginResult(PluginResult.Status.NO_RESULT);
pluginResult.setKeepCallback(true);
}
}
this is of course done in the exec function. because of the fact, that bluetooth events come not at certain points of time, i registered a broadcast receiver, that sends messages to my javascript, when theres is found an device for example.
if(BluetoothAdapter.ACTION_DISCOVERY_FINISHED.equals(action)) {
sendMessagetoJSCallback(new PluginResult(PluginResult.Status.OK, "Discovery finished."));
}
The belonging function for sending:
public void sendMessagetoJSCallback(PluginResult res) {
res.setKeepCallback(true);
success(res, mJSCallback);
}
What i did not really understand in that context is, what setKeepCallback does in those different functions. I thought there would be a documentation, but there isnt.
Can someone tell me? I orientated the development on https://github.com/phonegap/phonegap-plugins/tree/master/Android/PhoneListener