Issue
Just an example, I can get the Display Timeout setting like this:
int timeout = Settings.System.getInt(getContentResolver(), Settings.System.SCREEN_OFF_TIMEOUT);
I can set the Display Timeout setting like this:
Settings.System.putInt(getContentResolver(), Settings.System.SCREEN_OFF_TIMEOUT, 10000);
How can I programmatically get and set the Fast Charging and the Super Fast Charging settings?
Edit: Thanks to Veniamin for helping me get the correct variable names, here's what worked for me:
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();
}
Solution
You can read and update these settings in the Device Care
Samsung system application, so I reverse engineered it.
Here is how you can read Fast Charging, Super Fast Charging, and Fast Wireless Charging settings in your application:
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
Unfortunately, to update these settings programmatically, you need the android.permission.WRITE_SETTINGS permission is only granted to the system applications.
So, if you are not developing a system app, the only way to enable these settings is to ask users to enable them manually. To simplify workflow, you can route users directly to the system Fast Charging Settings
Activity, like so:
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
}
Since these settings are vendor-specific, checking the vendor id before reading them is recommended.
I tested it and confirm that it works on the Samsung Galaxy S20 (SM-G980F/DS); Android 12; One UI 4.1.
Answered By - Veniamin
Answer Checked By - Mildred Charles (JavaFixing Admin)