[mono-android] Calling Static JNI methods?
Stuart Lodge
me at slodge.com
Thu Feb 2 08:25:32 UTC 2012
Josh, Jon - thanks for posting this Flurry code - very helpful!
Seems to be working, plus I just added the extra call we need:
_flurryLogEvent = JNIEnv.GetStaticMethodID(_flurryClass,
"logEvent", "(Ljava/lang/String;)V");
called via
ExceptionSafe(() =>
JNIEnv.CallStaticVoidMethod(_flurryClass, _flurryLogEvent, new
JValue(new Java.Lang.String(eventName))));
Will know properly if it is working in the next few hours!
Stuart
On 7 December 2011 16:51, Josh Handel <Josh.Handel at catapultsystems.com>wrote:
> Sweet thanks (though the string value actually has to be a
> Java.Lang.String or it won't compile)
>
> For those interested, these are the two calls you need to track sessions
> in flurry (for testing, they have been dumped into where I am supposed to
> "call" them from, which is onStart and onStop of an activity you want to
> track.)
>
> protected override void OnStart()
> {
> base.OnStart();
> try
> {
> IntPtr Flurry_Class =
> JNIEnv.FindClass("com/flurry/android/FlurryAgent");
> IntPtr Flurry_onStartSession = JNIEnv.GetStaticMethodID
> (Flurry_Class, "onStartSession",
> "(Landroid/content/Context;Ljava/lang/String;)V");
> Java.Lang.String key = new Java.Lang.String("YOUR KEY
> HERE");
>
> JNIEnv.CallStaticVoidMethod(Flurry_Class,Flurry_onStartSession,new
> JValue(this),new JValue(key));
>
> }
> catch
> {
> }
> }
> protected override void OnStop()
> {
> base.OnStop();
> try
> {
> IntPtr Flurry_Class =
> JNIEnv.FindClass("com/flurry/android/FlurryAgent");
> IntPtr Flurry_onEndSession =
> JNIEnv.GetStaticMethodID(Flurry_Class, "onEndSession",
> "(Landroid/content/Context;)V");
> JNIEnv.CallStaticVoidMethod(Flurry_Class,
> Flurry_onEndSession, new JValue(this));
>
> }
> catch
> {
> }
> }
>
>
> Obviously it needs to be wrapped up cleaner into a utility library.. But
> these to actually work and send data to Flurry with Mono for Android 4.0
> just include the Flurry jar file. But looking at the Android logs, Flurry
> did get called, and send data to their analytics service.. So as a POC it
> does work :-)..
>
> Josh
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.ximian.com/pipermail/monodroid/attachments/20120202/199c9305/attachment.html>
More information about the Monodroid
mailing list