mirror of
https://github.com/kiwix/kiwix-android.git
synced 2025-08-03 18:56:44 -04:00
+ small imp
This commit is contained in:
parent
b88909e0ae
commit
8c69407987
@ -18,10 +18,10 @@ JNIEXPORT jboolean JNICALL Java_JNIKiwix_nativeLoadZIM
|
|||||||
/*
|
/*
|
||||||
* Class: JNIKiwix
|
* Class: JNIKiwix
|
||||||
* Method: nativeGetContent
|
* Method: nativeGetContent
|
||||||
* Signature: (Ljava/lang/String;LJNIKiwixString;LJNIKiwixInt;LJNIKiwixBool;)[B
|
* Signature: (Ljava/lang/String;LJNIKiwixString;LJNIKiwixInt;)[B
|
||||||
*/
|
*/
|
||||||
JNIEXPORT jbyteArray JNICALL Java_JNIKiwix_nativeGetContent
|
JNIEXPORT jbyteArray JNICALL Java_JNIKiwix_nativeGetContent
|
||||||
(JNIEnv *, jobject, jstring, jobject, jobject, jobject);
|
(JNIEnv *, jobject, jstring, jobject, jobject);
|
||||||
|
|
||||||
#ifdef __cplusplus
|
#ifdef __cplusplus
|
||||||
}
|
}
|
||||||
|
@ -1,7 +1,6 @@
|
|||||||
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,
|
public native byte[] nativeGetContent(String url, JNIKiwixString mimeType, JNIKiwixInt size);
|
||||||
JNIKiwixInt size, JNIKiwixBool isOk);
|
|
||||||
|
|
||||||
static {
|
static {
|
||||||
System.loadLibrary("kiwix");
|
System.loadLibrary("kiwix");
|
||||||
@ -15,11 +14,10 @@ public class JNIKiwix {
|
|||||||
|
|
||||||
JNIKiwixString mimeTypeObj = new JNIKiwixString();
|
JNIKiwixString mimeTypeObj = new JNIKiwixString();
|
||||||
JNIKiwixInt sizeObj = new JNIKiwixInt();
|
JNIKiwixInt sizeObj = new JNIKiwixInt();
|
||||||
JNIKiwixBool isOkObj = new JNIKiwixBool();
|
byte[] data = self.nativeGetContent("/A/Wikipedia.html", mimeTypeObj, sizeObj);
|
||||||
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(sizeObj.value);
|
||||||
System.out.println(isOkObj.value);
|
System.out.println(data[0]);
|
||||||
}
|
}
|
||||||
catch (Exception e) {
|
catch (Exception e) {
|
||||||
System.out.println("Message " + e.getMessage());
|
System.out.println("Message " + e.getMessage());
|
||||||
|
20
kiwix.c
20
kiwix.c
@ -1,6 +1,9 @@
|
|||||||
#include <jni.h>
|
#include <jni.h>
|
||||||
#include "JNIKiwix.h"
|
#include "JNIKiwix.h"
|
||||||
|
|
||||||
|
#include <stdio.h>
|
||||||
|
#include <string.h>
|
||||||
|
|
||||||
#include <iostream>
|
#include <iostream>
|
||||||
#include <string>
|
#include <string>
|
||||||
|
|
||||||
@ -42,10 +45,9 @@ void setStringObjValue(const std::string &value, const jobject obj, JNIEnv *env)
|
|||||||
}
|
}
|
||||||
|
|
||||||
void setIntObjValue(const int value, const jobject obj, JNIEnv *env) {
|
void setIntObjValue(const int value, const jobject obj, JNIEnv *env) {
|
||||||
int tmp = value;
|
|
||||||
jclass objClass = env->GetObjectClass(obj);
|
jclass objClass = env->GetObjectClass(obj);
|
||||||
jfieldID objFid = env->GetFieldID(objClass, "value", "I");
|
jfieldID objFid = env->GetFieldID(objClass, "value", "I");
|
||||||
env->SetIntField(obj, objFid, c2jni(tmp));
|
env->SetIntField(obj, objFid, value);
|
||||||
}
|
}
|
||||||
|
|
||||||
void setBoolObjValue(const bool value, const jobject obj, JNIEnv *env) {
|
void setBoolObjValue(const bool value, const jobject obj, JNIEnv *env) {
|
||||||
@ -60,12 +62,16 @@ JNIEXPORT jboolean JNICALL Java_JNIKiwix_nativeLoadZIM(JNIEnv *env, jobject obj,
|
|||||||
}
|
}
|
||||||
|
|
||||||
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);
|
setIntObjValue(42, sizeObj, env);
|
||||||
setBoolObjValue(false, isOkObj, env);
|
|
||||||
|
|
||||||
// Java program dies otherwise (please keep this "useless" line)
|
std::string cData = "This is great!";
|
||||||
std::cout << "";
|
jbyteArray data = env->NewByteArray(6);
|
||||||
|
jbyte *dataPointer = env->GetByteArrayElements(data, 0);
|
||||||
|
memcpy(dataPointer, cData.c_str(), c2jni(cData.size()));
|
||||||
|
env->ReleaseByteArrayElements(data, dataPointer, 0);
|
||||||
|
|
||||||
|
return data;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user