I’m having trouble calling a function from an android app.
I can’t figure out how to give arguments to callFunction. The result code is always 0 from android. I have a test println in the function that shows up on the serial monitor when called from the console.
I can log in, retrieve a list of functions, and get variable values without any issues. When I call the function from the console, the correct values show up in my app as variables when retrieved, I just need to be able to call my function from the app first instead of the console obviously.
public void getLocationString(View view) {
int resultCode = 0;
List<String> argument = new ArrayList<String>();
argument.add("get");
Toaster.s(MapsMarkerActivity.this, "Calling getCoords");
try {
mDevice.callFunction("getCoords");
resultCode = mDevice.callFunction("getCoords", argument);
} catch (ParticleDevice.FunctionDoesNotExistException | ParticleCloudException | IOException e) {
e.printStackTrace();
}
Toaster.s(MapsMarkerActivity.this, "Result of calling getCoords: " + resultCode);
}
the example doesn’t work for passing arguments, since list(“D7”, “1”) cannot be resolved, which is available in java 9 but java 9 won’t work in android studio. I can’t register a function to the cloud without the string argument, which I don’t even really need anyway. I have tried using argument.get(0), but it doesn’t work either. I’ve been searching the forums here, but can’t figure out how others got list(string, string) to work as a parameter. The getLocationString function is an onClick function that is invoked correctly from my app, it just gets lost somewhere on it’s way to or from my electron. The electron function:
int getGPSData(String command) {
if(command == "get"){
Serial.println("Called");
latitude = myGPS.getLatitude();// / 10000000.0;
//Serial.println(latitude);
longitude = myGPS.getLongitude();// / 10000000.0;
//Serial.println(longitude);
spd = myGPS.getGroundSpeed() / 278;
latString = "";
lonString = "";
spdString = "";
locString = "";
latString += String(latitude / 10000000.0);// + ".";
//if (latitude < 0) {
// latString += String((latitude * -1) % 10000000);
//}
//else {
// latString += String(latitude % 10000000);
//}
lonString += String(longitude / 10000000.0);// + ".";
//if (longitude < 0) {
// lonString += String((longitude * -1) % 10000000);
//}
//else {
// lonString += String(longitude % 10000000);
//}
spdString += String(spd);
locString += latString;
locString += ",";
locString += lonString;
return 1;
}
else{
return -1;
Serial.println("called");
}
}
Is the example kotlin or java? I’m working in java for my app.
Any advice?