Android install apk from url

My application checks if there is a new version of my application (my application is not included in the play store) and automatically downloads the apk file to 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 shows the popup window "Error parsing: problem with package parse"

In my AndroidManifest, I gave 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"/> 
+4
source share
3 answers

You need to add "file: //" in front of your file path. something like that:

 intent.setDataAndType(Uri.parse("file://" + filepath), "application/vnd.android.package-archive"); startActivity(intent); 
+3
source

Can you manually install the file, an error occurs while analyzing the package when apk has a damaged manifest file. Verify that the manual installation of the file you uploaded is actually performed.

+1
source

I had a similar error message. The root of my problem was that I saved the apk , which I uploaded to my application data directory instead of sdcard . By /sdcard/myprog.apk , I was able to complete the installation without any problems.

Since I was able to install the installation to work with loading a web browser, I had to find out where these downloads go, and then when I boot programmatically to save in the same place.

I found the following very useful for my update process: Download the file from Android and show the progress in ProgressDialog , then I used something similar to what you have for installation.

+1
source

Source: https://habr.com/ru/post/1413895/


All Articles