Android Question safe APK installation problem

zmrcic

Member
Licensed User
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)
 

Erel

B4X founder
Staff member
Licensed User
Longtime User
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.
 
Upvote 0

zmrcic

Member
Licensed User
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.
but Erel, here, you are saying that MY_PACKAGE_REPLACED can do the trick? or did I misunderstand something?

in manifest
B4X:
AddReceiverText(MyCustomService, <intent-filter>
<action android:name="android.intent.action.MY_PACKAGE_REPLACED" />
 </intent-filter>)

and in MyCustomService

B4X:
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
 
Upvote 0

Similar Threads

Replies
10
Views
5K
D
  • Article
Share My Creation APK-Installer
Replies
0
Views
3K
Deleted member 103
D
Top