1. Error message:
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
2. Error message: No permission to open compressed file
Unable to open zip '/data/data/com.my.app/cache/myapp.apk ': Permission denied.
3. Key points of knowledge:
(1) Do Application Mall development when we download APK encountered a situation is the download of the apk saved where? Two cases: one is saved in the SD card, one is saved in the memory of the machine itself. In order to ensure that we can use the App Store, the downloaded apk is best kept in memory, there may be some machines do not have SD card (this is not strange, some Android TV is not standard SD card).
(2) Application Mall multi-threaded download apk when there is no problem, the download of the APK packet is complete, with a U disk copy can also be installed. However, permission Denied is prompted during silent installation, but I have modified the APK permissions before installing this APK:
String[] command = { "chmod", "-R", "777", apkFile.getPath() };
ProcessBuilder builder = new ProcessBuilder(command);
try {
builder.start();
if (Debug.isDebug) {
Log.d("Download", "process builder start success");
}
break;
} catch (IOException e) {
connt = connt + 1;
if (connt >= 10) {
break;
} else {
Log.e("Download", "process builder start exception");
}
}
The problem is here, although the permissions are changed, but the function of modifying permissions
<pre name= "code" class= "java" >processbuilder builder = new Processbuilder (command);
Builder.start ();
is to start a new process.
in this case, there will be a thread asynchronous operation problem, namely: Modify the permissions of the process and the installation of the APK process is an asynchronous thread operation, may be installed before the APK permissions have not been modified to complete, so there is a hint permission Denied error.
4. Workaround:
After modifying the APK permissions, let the main thread sleep 500ms to 1000ms.
try {
Thread.sleep(500);
} catch (Exception e) {
e.printStackTrace();
}
End!