Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

INSTALL_NON_MARKET_APPS is deprecated as of API 21, what is alternative?

I need to check for option INSTALL_NON_MARKET_APPS on API 23 and API 24. So what is alternative for those APIs?

Currenty using this

boolean isNonPlayAppAllowed = false;
            try {
                isNonPlayAppAllowed = Settings.Global.getInt(null, Settings.Global.INSTALL_NON_MARKET_APPS, 0) == 1;
            } catch (Exception e) {
                e.printStackTrace();
            }

Edited after Karan Mer answer:

Using canRequestPackageInstalls() I am getting this message "Call requires API level 26", I need for API 23 and API 24.

like image 405
patonjo Avatar asked Sep 12 '25 03:09

patonjo


1 Answers

You need to use canRequestPackageInstalls () from PackageManager instead of INSTALL_NON_MARKET_APPS as mentioned in the docs here

public abstract boolean canRequestPackageInstalls ()

Checks whether the calling package is allowed to request package installs through package installer. Apps are encouraged to call this API before launching the package installer via intent Intent.ACTION_INSTALL_PACKAGE. Starting from Android O, the user can explicitly choose what external sources they trust to install apps on the device. If this API returns false, the install request will be blocked by the package installer and a dialog will be shown to the user with an option to launch settings to change their preference. An application must target Android O or higher and declare permission Manifest.permission.REQUEST_INSTALL_PACKAGES in order to use this API.

like image 196
karan Avatar answered Sep 14 '25 15:09

karan