access google apk library through reflection
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67
diff --git a/android-project/src/org/libsdl/app/SDLActivity.java b/android-project/src/org/libsdl/app/SDLActivity.java
index a717ef1..25cb789 100644
--- a/android-project/src/org/libsdl/app/SDLActivity.java
+++ b/android-project/src/org/libsdl/app/SDLActivity.java
@@ -7,6 +7,7 @@ import java.util.Arrays;
import java.util.Collections;
import java.util.Comparator;
import java.util.List;
+import java.lang.reflect.Method;
import android.app.*;
import android.content.*;
@@ -22,9 +23,6 @@ import android.graphics.*;
import android.media.*;
import android.hardware.*;
-import com.android.vending.expansion.zipfile.APKExpansionSupport;
-import com.android.vending.expansion.zipfile.ZipResourceFile;
-
/**
SDL Activity
*/
@@ -502,7 +500,12 @@ public class SDLActivity extends Activity {
}
// APK extension files support
- private ZipResourceFile expansionFile = null;
+
+ /** com.android.vending.expansion.zipfile.ZipResourceFile object or null. */
+ private Object expansionFile;
+
+ /** com.android.vending.expansion.zipfile.ZipResourceFile's getInputStream() or null. */
+ private Method expansionFileMethod;
public InputStream openAPKExtensionInputStream(String fileName) throws IOException {
// Get a ZipResourceFile representing a merger of both the main and patch files
@@ -510,11 +513,28 @@ public class SDLActivity extends Activity {
Integer mainVersion = Integer.parseInt(nativeGetHint("SDL_ANDROID_APK_EXPANSION_MAIN_FILE_VERSION"));
Integer patchVersion = Integer.parseInt(nativeGetHint("SDL_ANDROID_APK_EXPANSION_PATCH_FILE_VERSION"));
- expansionFile = APKExpansionSupport.getAPKExpansionZipFile(this, mainVersion, patchVersion);
+ try {
+ expansionFile = Class.forName("com.android.vending.expansion.zipfile.APKExpansionSupport")
+ .getMethod("getAPKExpansionZipFile", Context.class, int.class, int.class)
+ .invoke(null, this, mainVersion, patchVersion);
+
+ expansionFileMethod = expansionFile.getClass()
+ .getMethod("getInputStream", String.class);
+ } catch (Exception ex) {
+ ex.printStackTrace();
+ expansionFile = null;
+ expansionFileMethod = null;
+ }
}
// Get an input stream for a known file inside the expansion file ZIPs
- InputStream fileStream = expansionFile.getInputStream(fileName);
+ InputStream fileStream;
+ try {
+ fileStream = (InputStream)expansionFileMethod.invoke(expansionFile, fileName);
+ } catch (Exception ex) {
+ ex.printStackTrace();
+ fileStream = null;
+ }
if (fileStream == null) {
throw new IOException();