warning: [deprecation] getInstallerPackageName(String) in PackageManager has been deprecated

Reference: https://developer.android.com/reference/android/content/pm/PackageManager#getInstallerPackageName(java.lang.String)

This Method is deprecated from API level 30, so you can safely manage this situation with:

if (Build.VERSION.SDK_INT >= 30) {

    InstallSourceInfo isi = getContext()
        .getPackageManager()
        .getInstallSourceInfo(getContext()
        .getPackageName());

    // now, with an InstallSourceInfo object, you have access to three useful methods

    String initiating = isi.getInitiatingPackageName();
    String installing = isi.getInstallingPackageName();
    String originating = isi.getOriginatingPackageName();

} else { // continue to use the old version API

    String installerPackageName = getContext()
        .getPackageManager()
        .getInstallerPackageName(
            getContext().getPackageName()
        );
}

getInitiatingPackageName returns the name of the package that requested the installation, or null if not available. This is normally the same as the old getInstallerPackageName.

Leave a Reply

Your email address will not be published. Required fields are marked *