Android Question App downloaded from play store or not?

le_toubib

Active Member
Licensed User
Longtime User
Hi all,
Is there a way to tell whether my app was downloaded via Google play store ? Or any other store , or apk directly installed ?
 

Erel

B4X founder
Staff member
Licensed User
Longtime User
B4X:
Private Sub Button1_Click
    Log(IsFromGooglePlay)
End Sub

Private Sub IsFromGooglePlay As Boolean
    Dim installer As String = GetInstallerPackager
    Dim packages As List = Array("com.android.vending", "com.google.android.feedback")
    Return packages.IndexOf(installer) > -1
End Sub

Private Sub GetInstallerPackager As String
    Dim ctxt As JavaObject
    ctxt.InitializeContext
    Dim installer As JavaObject = ctxt.RunMethodJO("getPackageManager", Null).RunMethod("getInstallerPackageName", Array(Application.PackageName))
    If installer.IsInitialized = False Then Return "" Else Return installer.As(String) 'ignore
End Sub

Based on: https://stackoverflow.com/questions/37539949/detect-if-an-app-is-installed-from-play-store
I haven't tested it with an app installed from Google Play.
 
Upvote 0
Cookies are required to use this site. You must accept them to continue using the site. Learn more…