On Dec 7, 2011, at 11:16 AM, Josh Handel wrote:
> I am working on trying to wrap the Flurry API… Flurry uses static methods for 
> all of its calls.. I haven’t seen/figured out how to call static methods thru 
> JNI

JNI differentiates between instance and static members, so to lookup a static 
method you need JNIEnv.GetStaticMethodID():

        
http://androidapi.xamarin.com/?link=M:Android.Runtime.JNIEnv.GetStaticMethodID

Similarly, to invoke the method you'll need e.g. 
JNIEnv.CallStaticObjectMethod():

        
http://androidapi.xamarin.com/?link=M:Android.Runtime.JNIEnv.CallStaticObjectMethod

> or (better) use the new Register stuff to wrap the Flurry class (specificly 
> its static methods).

[Register] isn't used to implement the method invocation. [Register] is used to 
permit subclassing, interface implementation, and overriding/implementing 
class/interface methods. (It's used to control Android Callable Wrapper 
generation, i.e. Java generation, and thus doesn't do anything for the C# code 
you need to write.)

> I can locate the class via JNI or Java.Lang.Class.FromName()  but given these 
> are static methods not instance methods I’m not sure where to go next..
>  
> FlurryAgent.onStartSession(Context,"key");

As always, use `javap -s ...` to determine the correct JNI signature. I'll just 
guess for demonstration purposes, though:

        IntPtr FlurryAgent_Class = JNIEnv.FindClass ("package/of/FlurryAgent");
        IntPtr FlurryAgent_onStartSession = JNIEnv.GetStaticMethodID 
(FlurryAgent_Class,
                        "onStartSession", 
"(Landroid/content/Context;Ljava/lang/String;)V");
        JNIEnv.CallStaticVoidMethod (FlurryAgent_Class, 
FlurryAgent_onStartSession,
                        new JValue (Context), new JValue ("key"));


> FlurryAgent.onStopSession(Context);

        IntPtr FlurryAgent_onStopSession = JNIEnv.GetStaticMethodID 
(FlurryAgent_Class,
                        "onStartSession", "(Landroid/content/Context;)V");
        JNIEnv.CallStaticVoidMethod (FlurryAgent_Class, 
FlurryAgent_onStopSession,
                        new JValue (Context));

 - Jon

_______________________________________________
Monodroid mailing list
Monodroid@lists.ximian.com

UNSUBSCRIBE INFORMATION:
http://lists.ximian.com/mailman/listinfo/monodroid

Reply via email to