summaryrefslogtreecommitdiff
path: root/platform/android
diff options
context:
space:
mode:
authorMatt Holgate <matt@emobix.co.uk>2014-07-02 18:05:43 +0100
committerMatt Holgate <matt@emobix.co.uk>2014-07-02 18:05:43 +0100
commitfe01358a4e3cf8e8c1d625937f89ddb9c1a7d8dc (patch)
tree03b31b2a834e695b717f70945bae0c8603fa53cd /platform/android
parent8d62114762092e31f3465e17d764d92c94ac4fa5 (diff)
downloadmupdf-fe01358a4e3cf8e8c1d625937f89ddb9c1a7d8dc.tar.xz
Pass mimetype when opening a document from a stream.
Fixes opening non-PDF files from email programs that use a ContentProvider to supply attachments.
Diffstat (limited to 'platform/android')
-rw-r--r--platform/android/jni/mupdf.c16
-rw-r--r--platform/android/src/com/artifex/mupdfdemo/MuPDFActivity.java6
-rw-r--r--platform/android/src/com/artifex/mupdfdemo/MuPDFCore.java7
3 files changed, 20 insertions, 9 deletions
diff --git a/platform/android/jni/mupdf.c b/platform/android/jni/mupdf.c
index 04f1ceff..b9578d44 100644
--- a/platform/android/jni/mupdf.c
+++ b/platform/android/jni/mupdf.c
@@ -408,13 +408,14 @@ static void bufferStreamSeek(fz_stream *stream, int offset, int whence)
}
JNIEXPORT jlong JNICALL
-JNI_FN(MuPDFCore_openBuffer)(JNIEnv * env, jobject thiz)
+JNI_FN(MuPDFCore_openBuffer)(JNIEnv * env, jobject thiz, jstring jmagic)
{
globals *glo;
fz_context *ctx;
jclass clazz;
fz_stream *stream = NULL;
buffer_state *bs;
+ const char *magic;
#ifdef NDK_PROFILER
monstartup("libmupdf.so");
@@ -432,11 +433,20 @@ JNI_FN(MuPDFCore_openBuffer)(JNIEnv * env, jobject thiz)
glo->thiz = thiz;
buffer_fid = (*env)->GetFieldID(env, clazz, "fileBuffer", "[B");
+ magic = (*env)->GetStringUTFChars(env, jmagic, NULL);
+ if (magic == NULL)
+ {
+ LOGE("Failed to get magic");
+ free(glo);
+ return 0;
+ }
+
/* 128 MB store for low memory devices. Tweak as necessary. */
glo->ctx = ctx = fz_new_context(NULL, NULL, 128 << 20);
if (!ctx)
{
LOGE("Failed to initialise context");
+ (*env)->ReleaseStringUTFChars(env, jmagic, magic);
free(glo);
return 0;
}
@@ -458,7 +468,7 @@ JNI_FN(MuPDFCore_openBuffer)(JNIEnv * env, jobject thiz)
fz_try(ctx)
{
glo->current_path = NULL;
- glo->doc = fz_open_document_with_stream(ctx, "", stream);
+ glo->doc = fz_open_document_with_stream(ctx, magic, stream);
alerts_init(glo);
}
fz_catch(ctx)
@@ -482,6 +492,8 @@ JNI_FN(MuPDFCore_openBuffer)(JNIEnv * env, jobject thiz)
glo = NULL;
}
+ (*env)->ReleaseStringUTFChars(env, jmagic, magic);
+
return (jlong)(intptr_t)glo;
}
diff --git a/platform/android/src/com/artifex/mupdfdemo/MuPDFActivity.java b/platform/android/src/com/artifex/mupdfdemo/MuPDFActivity.java
index bf652d92..062bb03b 100644
--- a/platform/android/src/com/artifex/mupdfdemo/MuPDFActivity.java
+++ b/platform/android/src/com/artifex/mupdfdemo/MuPDFActivity.java
@@ -223,12 +223,12 @@ public class MuPDFActivity extends Activity implements FilePicker.FilePickerSupp
return core;
}
- private MuPDFCore openBuffer(byte buffer[])
+ private MuPDFCore openBuffer(byte buffer[], String magic)
{
System.out.println("Trying to open byte buffer");
try
{
- core = new MuPDFCore(this, buffer);
+ core = new MuPDFCore(this, buffer, magic);
// New file: drop the old outline data
OutlineActivityData.set(null);
}
@@ -314,7 +314,7 @@ public class MuPDFActivity extends Activity implements FilePicker.FilePickerSupp
}
}
if (buffer != null) {
- core = openBuffer(buffer);
+ core = openBuffer(buffer, intent.getType());
} else {
core = openFile(Uri.decode(uri.getEncodedPath()));
}
diff --git a/platform/android/src/com/artifex/mupdfdemo/MuPDFCore.java b/platform/android/src/com/artifex/mupdfdemo/MuPDFCore.java
index 68aed29e..0532b61d 100644
--- a/platform/android/src/com/artifex/mupdfdemo/MuPDFCore.java
+++ b/platform/android/src/com/artifex/mupdfdemo/MuPDFCore.java
@@ -25,7 +25,7 @@ public class MuPDFCore
/* The native functions */
private native long openFile(String filename);
- private native long openBuffer();
+ private native long openBuffer(String magic);
private native String fileFormatInternal();
private native boolean isUnencryptedPDFInternal();
private native int countPagesInternal();
@@ -114,10 +114,9 @@ public class MuPDFCore
isUnencryptedPDF = isUnencryptedPDFInternal();
}
- public MuPDFCore(Context context, byte buffer[]) throws Exception
- {
+ public MuPDFCore(Context context, byte buffer[], String magic) throws Exception {
fileBuffer = buffer;
- globals = openBuffer();
+ globals = openBuffer(magic != null ? magic : "");
if (globals == 0)
{
throw new Exception(context.getString(R.string.cannot_open_buffer));