Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>You're in luck, Java and Android both use the Unicode character set. However, Android (by default) use the UTF-8 encoding, which JNI doesn't intrisically support. Nonetheless, Java classes are fully capable of converting between character set encodings. The <code>lang.java.String</code> constructors allow you to specify a character set/encoding or use the OS-default, which on Android, of course, is coded as UTF-8.</p> <p>To make it easier (I prefer coding in Java, minimizing code that calls the JNI library), create an overload of your method and do some of the implementation in Java:</p> <pre><code>private static byte[] getLevelFile(byte[] levelName) { return getLevelFile(new String(levelName)).getBytes(); } </code></pre> <p>Now the JNI code only has to deal with jbytearray, both for the parameter and the return value:</p> <pre><code>JniMethodInfoJavaApi methodInfo; if (! getStaticMethodInfo(methodInfo, "getLevelFile", "([B)[B")) { return std::string(""); } LOGD("calling getLevelFile"); int nameLength = levelName.length(); jbyteArray nameBytes = methodInfo.env-&gt;NewByteArray(nameLength); methodInfo.env-&gt;SetByteArrayRegion(nameBytes, 0, nameLength, reinterpret_cast&lt;const jbyte*&gt;(levelName.c_str())); jbyteArray returnString = (jbyteArray) methodInfo.env-&gt;CallStaticObjectMethod(methodInfo.classID, methodInfo.methodID, nameBytes); LOGD("returned from getLevelFile"); methodInfo.env-&gt;DeleteLocalRef(methodInfo.classID); methodInfo.env-&gt;DeleteLocalRef(nameBytes); int returnLength = methodInfo.env-&gt;GetArrayLength(returnString); std::string data; data.reserve(returnLength); methodInfo.env-&gt;GetByteArrayRegion(returnString, 0, returnLength, reinterpret_cast&lt;jbyte*&gt;(&amp;data[0])); methodInfo.env-&gt;DeleteLocalRef(returnString); LOGD("returning Level data"); return data; </code></pre>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload