我知道有几个与此类似的问题,ConnectionManager.getRestrictBackgroundStatus()
会告诉我是否为我的应用禁用了后台数据。
对于我的用例,我想特别了解是否为所有应用程序启用了数据保护程序
settings-> dataSaver-> restrictBackgroundData
或特定的应用背景数据被禁用
app_Name-> Info-> Network-> disable_backgroundData
ConnectionManager.getRestrictBackgroundStatus()
在两种情况下都会给我相同的答案,我怎么知道启用了哪个特定设置?
由于Android Lollipop,我们有了isPowerSaveMode(),这是示例-
PowerManager powerManager = (PowerManager)
getActivity().getSystemService(Context.POWER_SERVICE);
if (android.os.Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP
&& powerManager.isPowerSaveMode()) {
// Animations are disabled in power save mode, so just show a toast instead.
Toast.makeText(mContext, getString(R.string.toast), Toast.LENGTH_SHORT).show();
}