following Version safe APK installation I have managed to download and install new version of my app from my site. Everything is working just fine, except when I install new version, it won't start automatically, must find it on apps and start it. I see it is new version, have label for that....
what am I doing wrong?
thanks....
B4X:
Dim ApkName As String = "someapp.apk"
Dim i As Intent
If Phone.SdkVersion >= 24 Then
i.Initialize("android.intent.action.INSTALL_PACKAGE", CreateFileProviderUri(Starter.Provider.SharedFolder, ApkName))
i.Flags = Bit.Or(i.Flags, 1) 'FLAG_GRANT_READ_URI_PERMISSION
Else
i.Initialize(i.ACTION_VIEW, "file://" & File.Combine(Starter.Provider.SharedFolder, ApkName))
i.SetType("application/vnd.android.package-archive")
End If
StartActivity(i)
The user has an option to open the app after installation. I don't think that it is possible to start the app automatically. The process is killed while the app is installed.
There is a "package replaced" intent that you might be able to intercept with a broadcast receiver but this will not be enough to start the activity.
well....
somehow I did it, although I think it is not the proper way....
looking over the internet I found different articles about PACKAGE_REPLACED, PACKAGE_REMOVED.....
The user has an option to open the app after installation. I don't think that it is possible to start the app automatically. The process is killed while the app is installed.
There is a "package replaced" intent that you might be able to intercept with a broadcast receiver but this will not be enough to start the activity.
Sub Service_Start (StartingIntent As Intent)
Log(StartingIntent.Action & " ----------------------------------------")
If StartingIntent.Action = "android.intent.action.MY_PACKAGE_REPLACED" Then
StartActivity(Main)
End If
Service.StopAutomaticForeground
End Sub
1. You should use a receiver instead of a service.
2. You cannot call StartActivity when the app is not visible, unless you have the special "draw over apps" permission.