mirror of
https://github.com/kiwix/kiwix-android.git
synced 2025-09-09 07:16:04 -04:00
+ few new methods
This commit is contained in:
parent
5348c75c31
commit
b88909e0ae
@ -18,10 +18,10 @@ JNIEXPORT jboolean JNICALL Java_JNIKiwix_nativeLoadZIM
|
|||||||
/*
|
/*
|
||||||
* Class: JNIKiwix
|
* Class: JNIKiwix
|
||||||
* Method: nativeGetContent
|
* Method: nativeGetContent
|
||||||
* Signature: (Ljava/lang/String;)Ljava/lang/String;
|
* Signature: (Ljava/lang/String;LJNIKiwixString;LJNIKiwixInt;LJNIKiwixBool;)[B
|
||||||
*/
|
*/
|
||||||
JNIEXPORT jstring JNICALL Java_JNIKiwix_nativeGetContent
|
JNIEXPORT jbyteArray JNICALL Java_JNIKiwix_nativeGetContent
|
||||||
(JNIEnv *, jobject, jstring);
|
(JNIEnv *, jobject, jstring, jobject, jobject, jobject);
|
||||||
|
|
||||||
#ifdef __cplusplus
|
#ifdef __cplusplus
|
||||||
}
|
}
|
||||||
|
@ -1,6 +1,7 @@
|
|||||||
public class JNIKiwix {
|
public class JNIKiwix {
|
||||||
public native boolean nativeLoadZIM(String path);
|
public native boolean nativeLoadZIM(String path);
|
||||||
public native byte[] nativeGetContent(String url, JNIKiwixString mimeType, JNIKiwixInt size);
|
public native byte[] nativeGetContent(String url, JNIKiwixString mimeType,
|
||||||
|
JNIKiwixInt size, JNIKiwixBool isOk);
|
||||||
|
|
||||||
static {
|
static {
|
||||||
System.loadLibrary("kiwix");
|
System.loadLibrary("kiwix");
|
||||||
@ -14,8 +15,11 @@ public class JNIKiwix {
|
|||||||
|
|
||||||
JNIKiwixString mimeTypeObj = new JNIKiwixString();
|
JNIKiwixString mimeTypeObj = new JNIKiwixString();
|
||||||
JNIKiwixInt sizeObj = new JNIKiwixInt();
|
JNIKiwixInt sizeObj = new JNIKiwixInt();
|
||||||
self.nativeGetContent("/A/Wikipedia.html", mimeTypeObj, sizeObj);
|
JNIKiwixBool isOkObj = new JNIKiwixBool();
|
||||||
|
self.nativeGetContent("/A/Wikipedia.html", mimeTypeObj, sizeObj, isOkObj);
|
||||||
System.out.println(mimeTypeObj.value);
|
System.out.println(mimeTypeObj.value);
|
||||||
|
System.out.println(sizeObj.value);
|
||||||
|
System.out.println(isOkObj.value);
|
||||||
}
|
}
|
||||||
catch (Exception e) {
|
catch (Exception e) {
|
||||||
System.out.println("Message " + e.getMessage());
|
System.out.println("Message " + e.getMessage());
|
||||||
@ -33,3 +37,7 @@ class JNIKiwixString {
|
|||||||
class JNIKiwixInt {
|
class JNIKiwixInt {
|
||||||
int value;
|
int value;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
class JNIKiwixBool {
|
||||||
|
boolean value;
|
||||||
|
}
|
21
kiwix.c
21
kiwix.c
@ -41,12 +41,31 @@ void setStringObjValue(const std::string &value, const jobject obj, JNIEnv *env)
|
|||||||
env->SetObjectField(obj, objFid, c2jni(value, env));
|
env->SetObjectField(obj, objFid, c2jni(value, env));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void setIntObjValue(const int value, const jobject obj, JNIEnv *env) {
|
||||||
|
int tmp = value;
|
||||||
|
jclass objClass = env->GetObjectClass(obj);
|
||||||
|
jfieldID objFid = env->GetFieldID(objClass, "value", "I");
|
||||||
|
env->SetIntField(obj, objFid, c2jni(tmp));
|
||||||
|
}
|
||||||
|
|
||||||
|
void setBoolObjValue(const bool value, const jobject obj, JNIEnv *env) {
|
||||||
|
jclass objClass = env->GetObjectClass(obj);
|
||||||
|
jfieldID objFid = env->GetFieldID(objClass, "value", "Z");
|
||||||
|
env->SetIntField(obj, objFid, c2jni(value));
|
||||||
|
}
|
||||||
|
|
||||||
/* 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 jbyteArray 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) {
|
jobject mimeTypeObj, jobject sizeObj,
|
||||||
|
jobject isOkObj) {
|
||||||
setStringObjValue("42", mimeTypeObj, env);
|
setStringObjValue("42", mimeTypeObj, env);
|
||||||
|
setIntObjValue(42, sizeObj, env);
|
||||||
|
setBoolObjValue(false, isOkObj, env);
|
||||||
|
|
||||||
|
// Java program dies otherwise (please keep this "useless" line)
|
||||||
|
std::cout << "";
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user