Created
May 8, 2021 08:59
-
-
Save suvasish114/67db5bbdc794bbe6e3aed47ba9bda471 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include<jni.h> | |
#include<stdio.h> | |
#include "NativeDemo.h" | |
JNIEXPORT void JNICALL Java_NativeDemo_test(JNIEnv *env, jobject obj){ | |
jclass cls; | |
jfieldID fid; | |
jint i; | |
printf("Inside native method."); | |
cls = (*env) ->GetObjectClass(env, obj); | |
fid = (*env) ->GetFieldID(env, cls, "i", "I"); | |
if(fid == 0){ | |
printf("Could not get field ID."); | |
return; | |
} | |
i=(*env)->GetIntField(env, obj, fid); | |
printf("i = %d\n", i); | |
(*env)->SetIntField(env, obj, fid, 2*i); | |
printf("Ending of native method."); | |
// function body | |
printf("Hello world"); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment