Friday, June 11, 2010

Access Java Class Variables from NDK

Access Java class variables from NDK (non-static function) in C:

  • env and obj are the first two parameters of the NDK function
  • "Ljava/lang/String;" is called the field descriptor of type String

Field Descriptor of other Variable Types:

  • Remember the semi-colon
  • Replace "Get" by "Set" for Set Field Functions

Field Descriptor Type Get Field Function
Z boolean GetBooleanField
B byte GetByteField
C char GetCharField
S short GetShortField
I int GetIntField
J long GetLongField
F float GetFloatField
D double GetDoubleField
Ljava/lang/String; String GetObjectField
[I int[] GetObjectField, and then cast it to an array
jintArray *arr = reinterpret_cast<jintArray*>(&data);
[Ljava/lang/Object; object[] GetObjectField, and then cast it to an array

No comments:

Post a Comment