2

I know this question has been asked many times before, but none of the solutions solved my issue. I have an APK saved on internal memory: "/data/data/[package-name]/files/0.apk" I saved it using:

openFileOutput("0.apk", Context.MODE_WORLD_READABLE);

I want to install it using the following code, but I am getting "There was a problem parsing the package"

Intent intent = new Intent(Intent.ACTION_VIEW);
intent.setDataAndType(Uri.fromFile(new File(context.getFilesDir(), "0.apk")), "application/vnd.android.package-archive");
context.startActivity(intent);

And LogCat says, "Parse error when parsing manifest. Discontinuing installation". Please help me solve this problem.

Edit: I decided to use external storage for my file. When I copied my file to the sd card and tried to install it by the above code, everything was alright. But when I downloaded the apk and stored it on sd card, the same "Parse error..." showed up again. At first, I assumed that it's because of a corrupted apk, but when I tried to install it outside my app, it worked.

Mbt925
  • 1,317
  • 1
  • 16
  • 31

2 Answers2

3

The "Parse error when parsing manifest. Discontinuing installation" error usually shows up when you are trying to install an app that is already installed by other means. For instance if you have an app with the same package name that you installed through the PlayStore and now you are trying to install form adb or vice versa.

Another option that will probably give less headaches, is to copy the apk to the users external storage folder, and then try to open it.

Juan Cortés
  • 20,634
  • 8
  • 68
  • 91
  • The app is not installed on the device. I don't want to use external storage, because maybe a device has not one! – Mbt925 Mar 09 '14 at 12:03
  • 1
    Every Android-compatible device supports a shared "external storage" that you can use to save files. This can be a removable storage media (such as an SD card) or an internal (non-removable) storage. Files saved to the external storage are world-readable and can be modified by the user when they enable USB mass storage to transfer files on a computer. http://developer.android.com/guide/topics/data/data-storage.html#filesExternal – Juan Cortés Mar 09 '14 at 12:05
  • I see. You say it's impossible for a device to haven't an external storage? – Mbt925 Mar 09 '14 at 12:55
  • That's what the docs say, you can rely on it at least to copy the apk for installing, and then deleting the file. – Juan Cortés Mar 09 '14 at 13:14
  • Ok, The file will be downloaded from internet and cached for future reference, so i can't delete it. Thanks anyway – Mbt925 Mar 09 '14 at 13:18
  • I edited my question. I am getting the same error for external storage. This time just for downloaded apk! – Mbt925 Mar 09 '14 at 14:33
  • 1
    @Juan-devtopia.coop - that's a slightly mistaken conclusion - on devices where the external storage is removable, it is subject to being removed. And on devices where USB Mass Storage mode is implemented, it is also subject to being *unavailable* while mounted to a PC. – Chris Stratton Mar 09 '14 at 16:07
  • 1
    @Mbt925 - try using a file manager app to click on and install the copy you moved to external storage - it may be the problem is with the apk, not your program. – Chris Stratton Mar 09 '14 at 16:09
  • @ChrisStratton-I checked it the first thing, but as i said in my question, the apk was not corrupted. – Mbt925 Mar 09 '14 at 16:12
0

It might be caused by the permission issue. Please copy the apk file to the external storage instead.

Robin
  • 10,052
  • 6
  • 31
  • 52
  • Hi. I'm facing this problem. If I move the apk to the external storage, it works fine, but I don't want to do that for security reasons (client requirement). Is there another way of making it work using internal storage? – Kuri May 11 '17 at 02:23