Repeat a call to Android Device

Alright. I have a plugin that will return my position using Combain SDK. This SDK returns my position. So what I want to do is start the locationupdates and then listen to new data. See it as System.out.printLine, but I want Ionic to listen(subscribe?) when new data exists. And this is like every 5 seconds.

The plugin is up and running, so my question is how do I listen to changes for specifically that function?

Javascript for plugin:
CombainSDK.prototype.requestLocation = function(successCallback, errorCallback){
exec(successCallback, errorCallback, ‘CombainSDK’, ‘requestLocation’, []);
}

Java for plugin:
– Code above –
else if(“bootSDK”.equals(action)){
this.initializeSDK();
if(this.sdk != null){
callbackContext.success(“SDK seems to have booted”);
}else{
callbackContext.error(“Something went wrong initializing the SDK”);
}
return true;
}else if(“requestLocation”.equals(action)){
this.handleLocationPermission();
this.requestLocation();
callbackContext.success(“Is it requesting?”);
}else {
return false;
}
return true;

public void initializeSDK(){
this.sdk = new CPSSDK(this.cordova.getActivity().getApplicationContext(), this.apiKey);
}

//Request location
public void requestLocation(){
    this.sdk.requestLocationUpdates(new LocationRequest(), new LocationCallback() {
        @Override
        public void onLocationAvailability(LocationAvailability locationAvailability) {
          super.onLocationAvailability(locationAvailability);
        }

        @Override
        public void onLocationResult(LocationResult locationResult) {
          super.onLocationResult(locationResult);  
        }
    }, null);
}

/Daniel

I’ve managed to call the function and get my position by logging out the result but it only happens once, what I want to do is subscribe to it and listen for data. But I am very unsure how Java can push back “Hello, we have new data for you”.

To clarify. I want to push data from Java up to Ionic when new location data exists. I’ve managed to alter an array when that happens. And with another function I’m then polling from Ionic to that Java Array, and that works. But it should be the other way around if it’s possible.

If anyone every goes in here and is looking for the same solution. Found it!

you need PluginResult.

Use it like this instead of callback.success()
setKeepCallback is the solution.

PluginResult pluginResult = new PluginResult(PluginResult.Status.OK, yourdatainjson);
pluginResult.setKeepCallback(true);
callbackContext.sendPluginResult(pluginResult);

Followed this thread here:
Explanation