Android Question Verify the app download from play store

QtechLab

Active Member
Licensed User
Longtime User
Hello programmers!

I found this java code on stackoverflow, it seems that with this function you can check if your app has been downloaded regulary from the play store or not.

B4X:
boolean verifyInstallerId(Context context) {
    // A list with valid installers package name
    List<String> validInstallers = new ArrayList<>(Arrays.asList("com.android.vending", "com.google.android.feedback"));

    // The package name of the app that has installed your app
    final String installer = context.getPackageManager().getInstallerPackageName(context.getPackageName());

    // true if your app has been downloaded from Play Store
    return installer != null && validInstallers.contains(installer);
}

Has B4A a similar function?
If not how can we implement this java code in our B4A apps? (something like the "NativeObject" for B4I).

---------------- EDIT ----------------
Implemented a solution with Java inline code:
B4X:
Sub Activity_Create(FirstTime As Boolean)
    'Do not forget to load the layout file created with the visual designer. For example:
    Activity.LoadLayout("Main")
   
    NativeObject.InitializeContext
    DownloadRegular = NativeObject.RunMethod("verifyInstallerId", Array(Reflector.GetContext))
    If DownloadRegular Then
        PanelOutput.Color = Colors.Green
        ToastMessageShow("App security ok", False)
    Else
        PanelOutput.Color = Colors.Red
        Msgbox("App security check failed", "Error")
    End If
   
End Sub


#IF JAVA
public boolean verifyInstallerId(android.content.Context context) {
    // A list with valid installers package name
    java.util.List<String> validInstallers = new java.util.ArrayList<String>(java.util.Arrays.asList("com.android.vending", "com.google.android.feedback"));

    // The package name of the app that has installed your app
    final String installer = context.getPackageManager().getInstallerPackageName(context.getPackageName());

    // true if your app has been downloaded from Play Store
    return installer != null && validInstallers.contains(installer);
}
#End If

Thanks in advance
Best Regards
 
Last edited:
Top