I did a project where I made a successful connection with my bluetooth plugin to my javascript. From my Javascript, I register my plugin callback this 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, of course, is done in the exec function. due to the fact that bluetooth events do not arrive at certain times, I registered a broadcast receiver that sends messages to my javascript when, for example, a device is found, for example.
if(BluetoothAdapter.ACTION_DISCOVERY_FINISHED.equals(action)) { sendMessagetoJSCallback(new PluginResult(PluginResult.Status.OK, "Discovery finished.")); }
Accessory function for sending:
public void sendMessagetoJSCallback(PluginResult res) { res.setKeepCallback(true); success(res, mJSCallback); }
In this context, I really don't understand what setKeepCallback does in these different functions. I thought there would be documentation, but not there.
Can anyone tell me? I oriented the development to https://github.com/phonegap/phonegap-plugins/tree/master/Android/PhoneListener
cordova phonegap-plugins
tellob
source share