如何以编程方式获取和设置"Super Fast Charging"设置?



举个例子,我可以得到这样的显示超时设置:

int timeout=Settings.System.getInt(getContentResolver((,Settings.System.SCREEN_OFF_timeout(;

我可以这样设置显示超时设置:

Settings.System.putInt(getContentResolver((,Settings.System.Screeen_OFF_TIMEOUT,10000(;

如何以编程方式获取和设置快速充电和超级快速充电设置

编辑:感谢Veniamin帮助我获得正确的变量名,以下是对我有效的方法:

try {
int isSuperFastChargingEnabled = Settings.System.getInt(getContentResolver(), "super_fast_charging");
if ( isSuperFastChargingEnabled == 0) {
Settings.System.putInt(getContentResolver(), "super_fast_charging", 1);
Settings.System.putInt(getContentResolver(), "adaptive_fast_charging", 1);
Toast.makeText(this, "Fast charge is set to 1",Toast.LENGTH_LONG).show();
} else if ( isSuperFastChargingEnabled == 1) {
Settings.System.putInt(getContentResolver(), "super_fast_charging", 0);
Settings.System.putInt(getContentResolver(), "adaptive_fast_charging", 0);
Toast.makeText(this, "Fast charge is set to 0",Toast.LENGTH_LONG).show();
}
} catch (Settings.SettingNotFoundException e) {
Toast.makeText(this,"Failed to get fast charge setting",Toast.LENGTH_LONG).show();
}

您可以在Device CareSamsung系统应用程序中读取和更新这些设置,所以我对其进行了逆向工程。

以下是您如何在应用程序中阅读快速充电超级快速充电无线快速充电置:

val isSuperFastChargingEnabled = Settings.System.getInt(context.contentResolver, "super_fast_charging", 0) == 1
val isFastChargingEnabled = Settings.System.getInt(context.contentResolver, "adaptive_fast_charging", 0) == 1
val isFastWirelessChargingEnabled = Settings.System.getInt(context.contentResolver, "wireless_fast_charging", 0) == 1

不幸的是,要以编程方式更新这些设置,您需要android.permission.WRITE_settings权限仅授予系统应用程序。

因此,如果你没有开发系统应用程序,启用这些设置的唯一方法就是要求用户手动启用它们。为了简化工作流程,您可以将用户直接路由到系统Fast Charging Settings活动,如下所示:

val intent = Intent()
intent.component = ComponentName(
"com.samsung.android.lool",
"com.samsung.android.sm.battery.ui.BatteryAdvancedMenuActivity"
)
// Activity class name may be updated in future versions, so
// the safest way to handle Activity class name updates is to wrap this
// call in the try/catch and add a custom error handling if the activity wasn't found.
try {
startActivity(intent)
} catch (e: Exception) {
// Custom error handling
}

由于这些设置是特定于供应商的,因此建议在读取它们之前检查供应商id。

我测试了它,并确认它适用于三星Galaxy S20(SM-G980F/DS(;安卓12;一个UI 4.1。

最新更新