Java class access from Android Webkit plugin

36 views
Skip to first unread message

Digambar Rasal

unread,
Dec 29, 2009, 10:58:17 AM12/29/09
to android-platform
Hi,

has anybody tried to access Java class from Android Webkit plugin?


I am trying to do but there is no reliable way to access with JNI. So
if anybody has tried please reply.


here is example of what I want -


JS in webage access plugin and plugin accesses JAVA class/application
to access Android platform and return result.


Regards
Digambar

douchuan

unread,
Dec 29, 2009, 8:58:42 PM12/29/09
to android-...@googlegroups.com
study the impl of Android-webkit-plugin, you will notice that instance
of JNIEnv is here.
ok, example:
EXPORT NPError NP_Initialize(NPNetscapeFuncs* browserFuncs,
NPPluginFuncs* pluginFuncs, void *java_env, void *application_context);

3rd arg is exactly JNIEnv.
you can do this:

static JavaVM *flashPluginJVM = 0;

NPError NP_Initialize(NPNetscapeFuncs* browserFuncs, NPPluginFuncs*
pluginFuncs, void *java_env, void *application_context)
{
...
if(flashPluginJVM == NULL) {
JNIEnv *jni = (JNIEnv *) java_env;
if( jni->GetJavaVM(&flashPluginJVM) < 0) {
LOGE("NP_Initialize GetJavaVM failed");
}
}
}

ok , now , you have instance of JavaVM. you can do anything you want to do.


Digambar Rasal 写道:

> --
>
> You received this message because you are subscribed to the Google Groups "android-platform" group.
> To post to this group, send email to android-...@googlegroups.com.
> To unsubscribe from this group, send email to android-platfo...@googlegroups.com.
> For more options, visit this group at http://groups.google.com/group/android-platform?hl=en.
>
>
>
>

Digambar Rasal

unread,
Dec 30, 2009, 6:23:31 AM12/30/09
to android-platform
Please excuse me for not being very clear.

I am using same method to get JavaEnv. But I can't find my
implemenation say com/example/testClass with JNI findclass. I can't
find any other class outside webkit also( not even com/android/*
classes).

In addition there are different ways to add Java class -
BUILD_JAVA_LIBRARY, BUILD_HOST_JAVA_LIBRARY or Application package but
none of this makes my Java code available in Webkit Plugin. For all it
gives error java.lang.NoClassDefFoundError

So now I am wondering is it possible to add Java implementation and
access it without changing/adding it to webkit code or am i missing
something,

Regards
Digambar

douchuan

unread,
Jan 4, 2010, 9:00:37 PM1/4/10
to android-...@googlegroups.com
Yes.
JNIEnv->FindClass work with system class. So, if you want to use it, you
must put your class into framework.
Or, you may try load your class by ClassLoader that point the path to
your class.

Digambar Rasal ??:

douchuan

unread,
Jan 4, 2010, 9:08:43 PM1/4/10
to do.c...@gmail.com, android-...@googlegroups.com
And, there is a tricky method. You may try that call
"android.webkit.WebView.addJavascriptInterface" first to add your
personal Object to JavaScript runtime, Then you can get it by Browser
function which exposed to plugin.
But, I haven't tried it, maybe it works.

douchuan 写道:

Reply all
Reply to author
Forward
0 new messages