INSTALL_NON_MARKET_APPS 自 API 起已弃用 21、什么是备选方案?
INSTALL_NON_MARKET_APPS is deprecated as of API 21, what is alternative?
我需要在 API 23 和 API 24 上检查选项 INSTALL_NON_MARKET_APPS。那么那些 API 的替代方案是什么?
目前正在使用这个
boolean isNonPlayAppAllowed = false;
try {
isNonPlayAppAllowed = Settings.Global.getInt(null, Settings.Global.INSTALL_NON_MARKET_APPS, 0) == 1;
} catch (Exception e) {
e.printStackTrace();
}
在 Karan Mer 回答后编辑:
使用 canRequestPackageInstalls() 我收到此消息 "Call requires API level 26",我需要 API 23 和 API 24。
您需要使用 PackageManager
中的 canRequestPackageInstalls ()
而不是文档 here
中提到的 INSTALL_NON_MARKET_APPS
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.
我需要在 API 23 和 API 24 上检查选项 INSTALL_NON_MARKET_APPS。那么那些 API 的替代方案是什么?
目前正在使用这个
boolean isNonPlayAppAllowed = false;
try {
isNonPlayAppAllowed = Settings.Global.getInt(null, Settings.Global.INSTALL_NON_MARKET_APPS, 0) == 1;
} catch (Exception e) {
e.printStackTrace();
}
在 Karan Mer 回答后编辑:
使用 canRequestPackageInstalls() 我收到此消息 "Call requires API level 26",我需要 API 23 和 API 24。
您需要使用 PackageManager
中的 canRequestPackageInstalls ()
而不是文档 here
INSTALL_NON_MARKET_APPS
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.