Home > database >  APK File not usable after download
APK File not usable after download

Time:01-11

I have a delicate Problem. I've built an App with an updatebutton. This almost has to download new apk files from a server. The App is not part of the play store, it is an closed system for our customers.

I am able to download via Chrome browser an open the file after download. Ok so far. When I try to download inside my app, the file is loaded an was usable until Android 8. After Android 8 I suppose, the file is like damaged, I cannot click to open it neither install. No errormessage occurs, the "download complete" event is fired by the downloadmanager every time.

compileSdkVersion 29
    minSdkVersion 23
    targetSdkVersion 29

I red many tutorials old and new, checked everyhting I could but nothing seem to work.

A bunch of code (kotlin) so far:

Download link is like "https:\myserver.com\foo\bar\MyApp.apk"

val r = DownloadManager.Request(Uri.parse(updateUri))

r.setMimeType(getMimeType(updateUri.toString()))
r.setTitle("MyApp.apk")
r.setDescription("Downloading attachment..")
r.allowScanningByMediaScanner()
r.setDestinationInExternalPublicDir(Environment.DIRECTORY_DOWNLOADS, "MyApp.apk")
                    r.setNotificationVisibility(DownloadManager.Request.VISIBILITY_VISIBLE_NOTIFY_COMPLETED)

val dm = activity.getSystemService(Context.DOWNLOAD_SERVICE) as DownloadManager
dm.enqueue(r)

Any hints?

CodePudding user response:

Ouch, finally found the solution, need to add <uses-permission android:name="android.permission.REQUEST_INSTALL_PACKAGES" /> to your manifest...

now it runs perfectly

  • Related