JNI Android ( src, res). (1), someshared-lib.c.
(1)
Java_YourPackageName_YourClassNameWhereYoudeclareYourNativeFunction_NativeFuntionName(JNIEnv* env,jobject thiz)
{
return (*env)->NewStringUTF(env, "<string to pass or you can mention jchar * type string >");
}
(2) IN java
package YourPackageName;
public class YourClassNameWhereYoudeclareYourNativeFunction extends Activity
{
public native String NativeFuntionName();
String returnValue = NativeFuntionName();
}
(3) Android.mk :
LOCAL_PATH: = $( my-dir)
$(CLEAR_VARS)
LOCAL_MODULE: = someshared-lib// lib , c
LOCAL_SRC_FILES: = someshared-lib.c// , (1)
$(BUILD_SHARED_LIBRARY)
ndk-build
( PATH =: $PATH
JNI, :
ndk-build
, someshared-lib lib, . apk device.To ,
/data/data/your_package_name/lib.
/data/data/your _package_name/lib (/system/lib) (JNI), Android.
, -, , c, :
Java_YourPackageName_YourClassNameWhereYoudeclareYourNativeFunction_NativeFuntionName(JNIEnv* env,jclass obj,jobject thiz)
{
jfieldID fid;
jboolean enable_flag;
//Pass the class object having all the variable from the android app to the JNI in the jclass obj and access its members using the field ID and using Get and Set firld ID.
clazz = (*env)->GetObjectClass(env, info);
fid = (*env)->GetFieldID(env,clazz,"some_variable","X"); //"X" - type of variable for boolean it //is Z , for INtezer it is I, for double it is D,
//for getting teh value fomr the JNI
enable_flag = (*env)->GetBooleanField(env, **thiz**, fid);
//for setting the value
fid = (*env)->GetFieldID(env,clazz,"other_float_variable","D");
(*env)->SetDoubleField(env,**thiz**,fid,other_float_variable);
}
Android .
,
(2) :
YourPackageName;
public class YourClassNameWhereYoudeclareYourNativeFunction extends Activity
{
public native String NativeFuntionName();
String returnValue = NativeFuntionName( exampleStruct exst);
exampleStruct:
public class exampleStruct {
protected boolean some_variable = 0;
protected float other_float_variable = 0;
}
}
, .