Android Question Install apk from App

BjoernB

Member
Licensed User
Hey everyone!


As part of an app update, we wanted to execute the newly downloaded APK file from within the app itself, and later from a separate app, as follows:


Code:
Sub Button1_Click
     Dim apkFile As String = File.Combine(File.DirRootExternal & "/Download", "skorb.apk")
     Dim i As Intent  
  
     If phone.SdkVersion >= 24 Then
         Log(Provider.GetFileUri(apkFile))                
         i.Initialize("android.intent.action.INSTALL_PACKAGE", Provider.GetFileUri(apkFile))
         i.Flags = Bit.Or(i.Flags, 3) 'FLAG_GRANT_READ_URI_PERMISSION)
         Provider.SetFileUriAsIntentData(i, "skorb.apk")
         i.SetType("application/vnd.android.package-archive")
     Else
        Provider.SetFileUriAsIntentData(i, apkFile)
        i.SetType("application/vnd.android.package-archive")
        i.Flags = Bit.Or(i.Flags, 1) ' FLAG_GRANT_READ_URI_PERMISSION
     End If
     StartActivity(i)   
End Sub


In both cases—whether from the app itself or the install-app, at "StartActivity(i)", we receive an error message stating that there is an issue with the package.
A Google search suggests that the permissions to install apps from unknown sources are not granted, but we have definitely ensured that they are enabled. We have checked this for both apps and the B4A Bridge.


A search in the forum led me to the B4A server, but the posts are from 2011 to 2014 and unfortunately no longer apply to modern Android versions.
What can I do to get the installation to work? The method doesn’t really matter in the end. Maybe I’m thinking in the wrong direction—does anyone have any ideas?
 

joergb

Member
Licensed User
Longtime User
Hallo Erel

thanks for your quick replay

your demo app run's. But know I have trouble to copy the downloaded file to your install-folder.
I search for it in the forum
 
Upvote 0

Similar Threads

Replies
8
Views
2K
Replies
10
Views
7K
D
  • Article
Share My Creation APK-Installer
Replies
0
Views
4K
Deleted member 103
D
Top