Search code examples
androidiosnativecordovaanalytics

From JavaScript, Trigger Native Code Function


I have a PhoneGap app that is using the Localytics services and I would like to track a certain event, so from the Javascript code at a certain moment I would like to call a native function with a few parameters. This native function would then call the event tracking function from Localytics like so:

NSDictionary *dictionary =
    [NSDictionary dictionaryWithObjectsAndKeys:
     @"miles per hour",
     @"display units",
     @"yes",
     @"blank screen",
     nil];
[[LocalyticsSession sharedLocalyticsSession] tagEvent:@"Options saved" attributes:dictionary];

Do you have an example of native code being called from JS and passing parameters?

Thanks!


Solution

  • There are a bunch of examples of JavaScript -> Java calls in the Phonegap plugins at https://github.com/purplecabbage/phonegap-plugins