I have a org.chromium.content_public.browser.MessagePayload
object in my Android NativeActivity from generating a WebView and then manually processing through the Looper messages.
I'm trying to get its contents, but from what I can tell some various places, I need to use a MessagePayloadJni
's static method getAsString
to get the payload's string.
But, I can't seem to FindClass("org/chromium/content/browser/MessagePayloadJni")
as it returns a java.lang.ClassNotFoundException
.
Is there some other mechanism I should be using to obtain a class reference to MessagePayloadJni
from a NativeActivity?
This isn't too hard. You can use reflection to obtain the field members, and it turns out that it just obfuscated the class name properties. In some versions of Android, you can access the b
for String
and c
for byte[]
fields of MessagePayload
and for others yet, you have to back out one more step and you can access the byte array for the MessagePayload
Object.
Regardless, while the class members are public, Android obfuscates the names of the members, yet you can still introspect into the objects manually and get the payload of the WebMessage inside of them.
This makes it possible to use the JNI exclusively to interact with WebMessages, see the following code that creates a looper and intercepts the data without calling looper.loop()
: https://github.com/cnlohr/rawdrawandroid/blob/a77293aadb95f59cb3c2e8987bc976c06bee5a65/test.c#L317-L418