Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Getting a Context from a NativeActivity

I have an application using NativeActivity. I want to call out into Java to do something that requires a Context (e.g., accessing TelephonyManager to query the IMEI).

How do I get a valid Context for my activity?

The ANativeActivity structure contains a variety of useful data for my application, such as the JavaVM, and JNI environment, etc. It also contains a jobject pointing at my NativeActivity's class object. What it doesn't contain is a jobject pointing at the NativeActivity's instance. I don't see anything useful in struct android_app, either.

It must be possible to do this; any ideas how?

like image 805
David Given Avatar asked Sep 02 '11 14:09

David Given


1 Answers

Despite its name the clazz member of ANativeActivity struct is actually pointing to android.app.NativeActivity instance.
Check this post for an example of using a JNI call from the Native Activity to Java code.

like image 176
Idolon Avatar answered Oct 28 '22 19:10

Idolon