2

I've been trying to find out how to install stored APK from internal memory, but I continually get errors.

I've tried getFilesDir() but it returns

08-14 03:18:09.127 10089-10089/? W/zipro: Error opening archive /data/user/0/package_name/files/app-release.apk: I/O Error

08-14 03:18:09.127 10089-10089/? D/asset: failed to open Zip archive '/data/user/0/package_name/files/app-release.apk'

08-14 03:18:09.127 10089-10089/? W/PackageInstaller: Parse error when parsing manifest. Discontinuing installation

I've also tried Environment.getDownloadCacheDirectory() but I get a similar result.

I am attempting to install on a non-rooted device, but I have signature level app permission.

How do I install app on a non-rooted device?

Even

public void installAPKManual(String filename) {
    Intent intent = new Intent(Intent.ACTION_VIEW);
    Uri uri = Uri.fromFile(new File(filename));
    intent.setDataAndType(uri, "application/vnd.android.package-archive");
    startActivity(intent);
}

doesn't work. Parse error.

Update

It works after I use

file.setReadable(true, false)

to get world readable permission, but I wonder if there is a better way?

John61590
  • 1,106
  • 1
  • 13
  • 29

1 Answers1

0

If you are trying to retrieve the file from Environment then you need storage permission.

or if you are trying to get the file from your private storage getCacheDir() or getFileDir() you don't need permission but you must use File Provider.

if these are not the case try to install the APK manually first and see that everything is ok with the APK or not!!!

seyed Jafari
  • 1,235
  • 10
  • 20