This file contains hidden or 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 <linux/fs.h> | |
#include <linux/init.h> | |
#include <linux/miscdevice.h> | |
#include <linux/module.h> | |
#include <asm/uaccess.h> | |
#include <linux/cdev.h> | |
#include <linux/errno.h> | |
#define DEVICENAME "hello_world" | |
#define READINGDATA "Hello World Reads!\n" |
This file contains hidden or 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
extern "C" | |
JNIEXPORT void JNICALL | |
Java_com_example_androidndk_1passing_1complex_1data_NativeLibrary_callTheCallBackMethod(JNIEnv *env, | |
jobject instance) { | |
// Get jclass of the instance | |
jclass jClassInstance = env->GetObjectClass(instance); | |
// Get java callback method | |
jmethodID callBackJava = env->GetMethodID(jClassInstance, "callBack", "(ILjava/lang/String;)V"); |
This file contains hidden or 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
public native void callTheCallBackMethod(); | |
private void callBack(int data, String stringValue) { | |
callBackInterface.callBackEvent(stringValue + String.valueOf(data)); | |
} |
This file contains hidden or 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
/** | |
* On Call Back From JNI Button Clicked Event | |
* | |
* @param view | |
*/ | |
public void onCallBackFromJNIClicked(View view) { | |
// Call JNI callback method | |
nativeLib.callTheCallBackMethod(); | |
} |
This file contains hidden or 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
extern "C" | |
JNIEXPORT jobject JNICALL | |
Java_com_example_androidndk_1passing_1complex_1data_NativeLibrary_getObjectFromJNI(JNIEnv *env, | |
jobject instance) { | |
// Create a jclass from actual Java object class path | |
jclass sampleObjClass = env->FindClass( | |
"com/example/androidndk_passing_complex_data/SampleDataObj"); | |
jmethodID methodId = env->GetMethodID(sampleObjClass, "<init>", "()V"); | |
jobject sampleObj = env->NewObject(sampleObjClass, methodId); |
This file contains hidden or 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
/** | |
* On Get Object From JNI Button Clicked Event | |
* | |
* @param view | |
*/ | |
public void onGetObjectFromJNI(View view) { | |
TextView textView = findViewById(R.id.textViewGetObjectFromJNI); | |
SampleDataObj dataObj = nativeLib.getObjectFromJNI(); | |
textView.setText(dataObj.getSampleString()); | |
} |
This file contains hidden or 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
extern "C" | |
JNIEXPORT jint JNICALL | |
Java_com_example_androidndk_1passing_1complex_1data_NativeLibrary_passObjectToJNI(JNIEnv *env, | |
jobject instance, | |
jobject sampleDataObj) { | |
// Get jclass of the object | |
jclass sampleDataOBJClass = env->GetObjectClass(sampleDataObj); | |
// Get data field IDs of the object |
This file contains hidden or 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
/** | |
* On Pass Object To JNI Button Clicked Event | |
* | |
* @param view | |
*/ | |
public void onPassObjectToJNI(View view) { | |
TextView textView = findViewById(R.id.textViewPassObjectToJNI); | |
//Create Sample Data Object | |
SampleDataObj sampleDataObj = new SampleDataObj(); | |
sampleDataObj.setSampleInt(0); |
This file contains hidden or 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
extern "C" | |
JNIEXPORT jint JNICALL | |
Java_com_example_androidndk_1passing_1complex_1data_NativeLibrary_passingDataToJni(JNIEnv *env, | |
jobject instance, | |
jdoubleArray tmpArray_, | |
jint tmpInt, | |
jfloat tmpFloat) { | |
jdouble *tmpArray = env->GetDoubleArrayElements(tmpArray_, NULL); | |
int ret = 0; |
This file contains hidden or 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
/** | |
* On Pass Data To JNI Button Clicked Event | |
* | |
* @param view | |
*/ | |
public void onPassDataToJNIButtonClicked(View view) { | |
TextView textView = findViewById(R.id.textViewPassDataToJNI); | |
// Temp data which passing to JNI | |
double[] tmpArray = {1, 2, 3}; | |
int tmpInt = 1; |