Hi there,

I am trying to add a javascript interface to my webview but it the
method in the object I pass to the webview does not get triggered. So
I searched around a bit and read that the class passed to the
Javascript Interface should be a Java Object with its methods exposed
to Java. I would preferably have all this in managed code, so I was
thinking whether it is possible to tell mandroid to put the methods in
the generated Java files, so that Java knows of them.

I remember Jonathan helping me solve a small problem with the
CreateItem method in the ItemizedOverlay through JNI, so I tried to do
something similar, not knowing much about what I was doing:

        public abstract class FixedAccessControlJavascriptNotify :
Java.Lang.Object
        {
            [Register("notify", "(Ljava/lang/String;)Z", "GetNotifyHelper")]
            public abstract Java.Lang.Boolean Notify(string
securityTokenResponse);

            static Delegate cb_Notify;
            static Delegate GetNotifyHelper()
            {
                if (cb_Notify == null)
                    cb_Notify =
JNINativeWrapper.CreateDelegate((Func<IntPtr, IntPtr, string,
IntPtr>)_Notify);

                return cb_Notify;
            }

            static IntPtr _Notify(IntPtr env, IntPtr __self, string
securityTokenResponse)
            {
                FixedAccessControlJavascriptNotify self =
Java.Lang.Object.GetObject<FixedAccessControlJavascriptNotify>(__self,
JniHandleOwnership.DoNotTransfer);
                Java.Lang.Boolean value = self.Notify(securityTokenResponse);
                return JNIEnv.ToJniHandle(value);
            }
        }

Implementing that class with:

        public class AccessControlJavascriptNotify :
FixedAccessControlJavascriptNotify
        {
            public Activity context;

            public AccessControlJavascriptNotify(Activity activity)
            {
                context = activity;
            }

            public override Java.Lang.Boolean Notify(string
securityTokenResponse)
            {

                return new Java.Lang.Boolean(true);
            }
        }

Though I end up getting errors from saying that there is no method to Overrride:

"C:\Users\tcielecki\Desktop\MonoDroid.WAToolkit\MonoDroid.WAToolkit\MonoDroid.WAToolkit.Sample.csproj"
(SignAndroidPackage target) (1) ->
(_CompileJava target) ->
  
obj\Debug\android\src\monodroid\watoolkit\library\login\AccessControlWebAuthActivity_AccessControlJavascriptNotify.java(22,2):
error :  method does not override or implement a method from a
supertype 
[C:\Users\tcielecki\Desktop\MonoDroid.WAToolkit\MonoDroid.WAToolkit\MonoDroid.WAToolkit.Sample.csproj]
obj\Debug\android\src\monodroid\watoolkit\library\login\AccessControlWebAuthActivity_AccessControlJavascriptNotify.java(22,2):
error :         @Override
[C:\Users\tcielecki\Desktop\MonoDroid.WAToolkit\MonoDroid.WAToolkit\MonoDroid.WAToolkit.Sample.csproj]
obj\Debug\android\src\monodroid\watoolkit\library\login\AccessControlWebAuthActivity_AccessControlJavascriptNotify.java(22,2):
error :  
[C:\Users\tcielecki\Desktop\MonoDroid.WAToolkit\MonoDroid.WAToolkit\MonoDroid.WAToolkit.Sample.csproj]

I guess the errors are right, because if I check the generated java
files FixedAccessControlJavascriptNotify does not have any methods to
override.

Not sure what I am doing here is the right way, but I just need that
simple notify method to get a token from that JavascriptInterface for
my app.
-- 
Med Venlig Hilsen / With Best Regards
Tomasz Cielecki
http://ostebaronen.dk
_______________________________________________
Monodroid mailing list
Monodroid@lists.ximian.com

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

Reply via email to