简体   繁体   中英

How do I convert two jlong data type to jstring and then concatenate both of the strings together in order to return a string to java from JNI?

My current C function in my jni class is:

JNIEXPORT jstring JNICALL
Java_com_example_hanif_liftsensor_DeviceControlActivity_encryptData( JNIEnv* env, jobject thiz , jlong data1 , jlong data2) {


vCRYPTO_ACT_Encryption((uint32_t *) data1, (uint32_t *) data2);

__android_log_print(ANDROID_LOG_DEBUG, "TRACKERS_RESULT", "%i", unCRYPTO_DAT_TmpV0_Buffer.un32); // need to convert back to string hex
__android_log_print(ANDROID_LOG_DEBUG, "TRACKERS_RESULT", "%i", unCRYPTO_DAT_TmpV1_Buffer.un32); // need to convert back to string hex
//after both converted to jstring then combine it to return as jstring


return jstring;

 }

I would like to convert both the unCRYPTO_DAT_TmpV0_Buffer.un32 & unCRYPTO_DAT_TmpV1_Buffer.un32 from jlong to jstring and then concatenate them as one jstring to return as a single jstring value. Thanks.

You could do that in JNI. But generally, if it can be done in Java, it is far easier there. Designing for this in Java, you create classes with public methods for your public interface, then implement parts with private native methods and add private classes and/or private members implemented in Java that make the JNI code simpler.

Try setting two long fields ( GetFieldID , SetLongField ) or returning the result of a constructor ( GetMethodID() with as the method name and void (V) as the return type , NewObjectV ) on a "results" class instead.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM