Reputation: 335
I am having an android application that is using an external jar that has in addition to regular classes an html file.
Meaning my final apk root directory looks something like this
How can I access from my application to the last file "helloworld.html"?
Upvotes: 1
Views: 3800
Reputation:
You have to replace the string "assets/SecureManifest.xml
" with your file "helloworld.html
"
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();
}
}
The github gist can be found here
Upvotes: 0
Reputation: 109257
Android package hierarchy is not a like java application package. So you can't access files like this.
I think you have to use this helloworld.html file in your application.
So put this file in /asset
directory and in your activity code just get file using
getAssets()
.
also access file like: file:///android_asset/helloworld.html
Upvotes: 1