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.
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With