Skip to content

Commit

Permalink
access google apk library through reflection
Browse files Browse the repository at this point in the history
  • Loading branch information
stopiccot committed Apr 30, 2014
1 parent 3cdae42 commit 3727528
Showing 1 changed file with 26 additions and 6 deletions.
32 changes: 26 additions & 6 deletions android-project/src/org/libsdl/app/SDLActivity.java
Expand Up @@ -7,6 +7,7 @@
import java.util.Collections;
import java.util.Comparator;
import java.util.List;
import java.lang.reflect.Method;

import android.app.*;
import android.content.*;
Expand All @@ -22,9 +23,6 @@
import android.media.*;
import android.hardware.*;

import com.android.vending.expansion.zipfile.APKExpansionSupport;
import com.android.vending.expansion.zipfile.ZipResourceFile;

/**
SDL Activity
*/
Expand Down Expand Up @@ -502,19 +500,41 @@ public static void pollInputDevices() {
}

// 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
if (expansionFile == null) {
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();
Expand Down

0 comments on commit 3727528

Please sign in to comment.