Reputation: 651
My application verify if there are a new version of my application (my application is not into play store) and download automatically the apk file into sdcard/download. Then I would like to start the installation and I use this code :
Intent intent = new Intent(Intent.ACTION_VIEW);
intent.setDataAndType(Uri.fromFile(new File(Environment.getExternalStorageDirectory() + "/download/" + "file.apk")), "application/vnd.android.package-archive");
startActivity(intent);
but it show the pop up "Parse Error:There is a problem parsing the package"
Into my AndroidManifest I have put the permission :
<uses-permission android:name="android.permission.INTERNET"/>
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/>
<uses-permission android:name="android.permission.INSTALL_PACKAGES"/>
<uses-permission android:name="android.permission.DELETE_PACKAGES"/>
Upvotes: 5
Views: 4938
Reputation: 3653
You need to add "file://" before your file's path. something like this:
intent.setDataAndType(Uri.parse("file://" + filepath), "application/vnd.android.package-archive");
startActivity(intent);
Upvotes: 0
Reputation: 20391
I had a similar error message. The root of my problem was that I was saving the apk
I downloaded to my application data
directory instead of a sdcard
. By saving to /sdcard/myprog.apk
I was able to do the install without any issues.
Since I was able to get the install to work from a web browser download, it was a matter of figuring out where those downloads go, then when I download programmatically to save in the same location.
I found the following very useful for my update process: Download a file with Android, and showing the progress in a ProgressDialog then I used something similar to what you have to do the install.
Upvotes: 2
Reputation: 189
Are you able to manually install the file, the error problem parsing the package comes, when an apk has a corrupt manifest file. Check if manual installation of the file you downloaded works in the first place.
Upvotes: 1