Sample Syntax Declaration for NDK

Getting Static String from JNI
              env->NewStringUTF("I am back with string!");

Access Fields Declared in java class (public float[] VertexCoords;)

1. jclass cls = env->GetObjectClass(obj); //obj is the object of java class
2. jfieldID fieldId = env->GetFieldID(cls, "VertexCoords", "[F");
                     // VertexCoords is the name of variable defined in java
                    // [F defines the type of variable it is array float
3. jobject objArray = env->GetObjectField (obj, fieldId);
                 // Take the field in jobject.
4. jfloatArray* fArray = reinterpret_cast<jfloatArray*>(&objArray);
               // Cast it to jfloatArray
5. jsize len = env->GetArrayLength(*fArray);
             //get the length of float array
6. float* data = env->GetFloatArrayElements(*fArray, 0);
            //get all data
after getting data perform the task according to your requirements

7. env->ReleaseFloatArrayElements(*fArray, data, 0);
          //Dont forget to release the pointer array


Access Methods Declared in java class (public int getFacetCount(){})

     jclass cls = env->GetObjectClass(obj);
    jmethodID methodId = env->GetMethodID(cls, "getFacetCount", "()I");
    int result = env->CallIntMethod(obj, methodId);


Popular posts from this blog

Bluetooth Data Transfer Example

DeCompile .apk file on ubuntu 14.04