mirror of
https://github.com/kiwix/kiwix-android.git
synced 2025-08-04 03:06:41 -04:00
+ few improvements.
This commit is contained in:
parent
7c405a54d3
commit
5348c75c31
@ -1,6 +1,6 @@
|
|||||||
public class JNIKiwix {
|
public class JNIKiwix {
|
||||||
public native boolean nativeLoadZIM(String path);
|
public native boolean nativeLoadZIM(String path);
|
||||||
public native String nativeGetContent(String url);
|
public native byte[] nativeGetContent(String url, JNIKiwixString mimeType, JNIKiwixInt size);
|
||||||
|
|
||||||
static {
|
static {
|
||||||
System.loadLibrary("kiwix");
|
System.loadLibrary("kiwix");
|
||||||
@ -11,6 +11,11 @@ public class JNIKiwix {
|
|||||||
|
|
||||||
try {
|
try {
|
||||||
self.nativeLoadZIM("test.zim");
|
self.nativeLoadZIM("test.zim");
|
||||||
|
|
||||||
|
JNIKiwixString mimeTypeObj = new JNIKiwixString();
|
||||||
|
JNIKiwixInt sizeObj = new JNIKiwixInt();
|
||||||
|
self.nativeGetContent("/A/Wikipedia.html", mimeTypeObj, sizeObj);
|
||||||
|
System.out.println(mimeTypeObj.value);
|
||||||
}
|
}
|
||||||
catch (Exception e) {
|
catch (Exception e) {
|
||||||
System.out.println("Message " + e.getMessage());
|
System.out.println("Message " + e.getMessage());
|
||||||
@ -20,3 +25,11 @@ public class JNIKiwix {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
class JNIKiwixString {
|
||||||
|
String value;
|
||||||
|
}
|
||||||
|
|
||||||
|
class JNIKiwixInt {
|
||||||
|
int value;
|
||||||
|
}
|
24
kiwix.c
24
kiwix.c
@ -13,6 +13,14 @@ jstring c2jni(const std::string &val, JNIEnv *env) {
|
|||||||
return env->NewStringUTF(val.c_str());
|
return env->NewStringUTF(val.c_str());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
jint c2jni(const int val) {
|
||||||
|
return (jint)val;
|
||||||
|
}
|
||||||
|
|
||||||
|
jint c2jni(const unsigned val) {
|
||||||
|
return (unsigned)val;
|
||||||
|
}
|
||||||
|
|
||||||
/* jni2c type conversion functions */
|
/* jni2c type conversion functions */
|
||||||
bool jni2c(const jboolean &val) {
|
bool jni2c(const jboolean &val) {
|
||||||
return val == JNI_TRUE;
|
return val == JNI_TRUE;
|
||||||
@ -22,11 +30,23 @@ std::string jni2c(const jstring &val, JNIEnv *env) {
|
|||||||
return std::string(env->GetStringUTFChars(val, 0));
|
return std::string(env->GetStringUTFChars(val, 0));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
int jni2c(const jint val) {
|
||||||
|
return (int)val;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Method to deal with variable passed by reference */
|
||||||
|
void setStringObjValue(const std::string &value, const jobject obj, JNIEnv *env) {
|
||||||
|
jclass objClass = env->GetObjectClass(obj);
|
||||||
|
jfieldID objFid = env->GetFieldID(objClass, "value", "Ljava/lang/String;");
|
||||||
|
env->SetObjectField(obj, objFid, c2jni(value, env));
|
||||||
|
}
|
||||||
|
|
||||||
/* Kiwix library functions */
|
/* Kiwix library functions */
|
||||||
JNIEXPORT jboolean JNICALL Java_JNIKiwix_nativeLoadZIM(JNIEnv *env, jobject obj, jstring path) {
|
JNIEXPORT jboolean JNICALL Java_JNIKiwix_nativeLoadZIM(JNIEnv *env, jobject obj, jstring path) {
|
||||||
return c2jni(true);
|
return c2jni(true);
|
||||||
}
|
}
|
||||||
|
|
||||||
JNIEXPORT jstring JNICALL Java_JNIKiwix_nativeGetContent(JNIEnv *env, jobject obj, jstring url) {
|
JNIEXPORT jbyteArray JNICALL Java_JNIKiwix_nativeGetContent(JNIEnv *env, jobject obj, jstring url,
|
||||||
|
jobject mimeTypeObj, jobject sizeObj) {
|
||||||
|
setStringObjValue("42", mimeTypeObj, env);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user