diff --git a/src/android/kiwixreader.cpp b/src/android/kiwixreader.cpp index 91dcec78b..f306d81e1 100644 --- a/src/android/kiwixreader.cpp +++ b/src/android/kiwixreader.cpp @@ -224,6 +224,21 @@ JNIEXPORT jstring JNICALL Java_org_kiwix_kiwixlib_JNIKiwixReader_getMimeType( return mimeType; } +JNIEXPORT jstring JNICALL Java_org_kiwix_kiwixlib_JNIKiwixReader_checkUrl( + JNIEnv* env, jobject obj, jstring url) +{ + jstring finalUrl; + std::string cUrl = jni2c(url, env); + try { + auto entry = READER->getEntryFromEncodedPath(cUrl); + entry = entry.getFinalEntry(); + finalUrl = c2jni(entry.getPath(), env); + } catch (std::exception& e) { + finalUrl = c2jni("", env); + } + return finalUrl; +} + JNIEXPORT jbyteArray JNICALL Java_org_kiwix_kiwixlib_JNIKiwixReader_getContent( JNIEnv* env, jobject obj, jobject url, jobject titleObj, jobject mimeTypeObj, jobject sizeObj) { diff --git a/src/android/org/kiwix/kiwixlib/JNIKiwixReader.java b/src/android/org/kiwix/kiwixlib/JNIKiwixReader.java index ea3a3d4b3..86f5f455b 100644 --- a/src/android/org/kiwix/kiwixlib/JNIKiwixReader.java +++ b/src/android/org/kiwix/kiwixlib/JNIKiwixReader.java @@ -38,6 +38,16 @@ public class JNIKiwixReader public native String getMimeType(String url); + /** + * Check if a url exists and is a redirect or not. + * + * Return an empty string if the url doesn't exist in the reader. + * Return the url of the "final" entry. + * - equal to the input url if the entry is not a redirection. + * - different if the url is a redirection (and the webview should redirect to it). + */ + public native String checkUrl(String url); + /** * Get the content of a article. *