Last active
December 21, 2015 11:21
-
-
Save packmad/eaf4e3e001a339d4e605 to your computer and use it in GitHub Desktop.
Read a file from another APK programmatically under Android
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public static InputStream getInputStreamFromApkResource(String apkFilePath, String apkResPath) throws IOException { | |
JarFile jarFile = new JarFile(apkFilePath); | |
JarEntry jarEntry = jarFile.getJarEntry(apkResPath); | |
return jarFile.getInputStream(jarEntry); | |
} | |
// Example usage reading the file "SecureManifest.xml" under "assets" folder: | |
File sdcard = Environment.getExternalStorageDirectory(); | |
File apkFile = new File(sdcard, "file.apk"); | |
if (apkFile.exists()) { | |
try { | |
InputStream is =getInputStreamFromApkResource(apkFile.toString(), "assets/SecureManifest.xml"); | |
BufferedReader br = new BufferedReader( new InputStreamReader(is)); | |
String str; | |
while ((str = br.readLine()) != null) { | |
Log.d("***", str); | |
} | |
} catch (IOException e) { | |
e.printStackTrace(); | |
} | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment