App Mall Download apk install package parsing error does not have permission Permission denied android-failed to open zip archive

Source: Internet
Author: User


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!





    



Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.