Android - failed to open zip archive

I download the apk file from the Internet and save it in Context.getCacheDir (). I upload the file via HttpURLConnection - I am not actually asking about the code (it works completely), so I am not posting it here. I am successfully starting the download. The file is downloaded to the cache, and then the installation is requested - but the system cannot open my APK and record an analysis error.

Therefore, the task is as follows:

03-31 16:48:43.740: INFO/ActivityManager(59): Start proc com.android.packageinstaller for activity com.android.packageinstaller/.PackageInstallerActivity: pid=620 uid=10026 gids={} 03-31 16:48:44.749: WARN/zipro(620): Unable to open zip '/data/data/com.my.app/cache/myApp.apk': Permission denied 03-31 16:48:44.749: DEBUG/asset(620): failed to open Zip archive '/data/data/com.my.app/cache/myApp.apk' 03-31 16:48:44.930: WARN/PackageParser(620): Unable to read AndroidManifest.xml of /data/data/com.my.app/cache/myApp.apk 03-31 16:48:44.930: WARN/PackageParser(620): java.io.FileNotFoundException: AndroidManifest.xml 

Problem: I do not have access to software / cache. Is there any way to solve this problem? I don’t want to use external storage as a download directory (the installation process works when I upload a file to external storage), the cache is large because the file will not be accessible to the average user from the file manager and what I want. Thanks for your thoughts.

This problem has been unsolvable for me for more than a month ...

Edit: There is still no solution, I'm trying to think I found 1st place, which is impossible with Android

Edit2: I must have looked poorly - my downloaded apk is in the cache ... Still there is no permission to allow installation from this directory?

+7
source share
3 answers

chmod 666 in the downloaded apk file before installing it in your code

more details:

 path = your_apk_file_path_in_cache_dir; permission="666"; try { String command = "chmod " + permission + " " + path; Runtime runtime = Runtime.getRuntime(); runtime.exec(command); } catch (IOException e) { e.printStackTrace(); } 
+6
source

This may help you:

 FileOutputStream fOutputStream = context.openFileOutput( fileName, Context.MODE_WORLD_READABLE); 
+2
source

I see what is happening ..

The cache cache is a cache managed by Android, which means that it can be cleared as soon as the internal memory starts to run low.

And if your application takes up too much cache space (which the APK probably does), when your application pauses / stops, Android can clear the cache directory.

To test this, do everything the way you did, and when the installation process starts, just start DDMS and see if the file is saved in the cache.

If not, then android cleared the application cache because it no longer works.

Try a different approach instead of context.getCacheDir() try context.getFilesDir()

+1
source

All Articles