Is there to a way to check the systems theme at run-time? (see image below)
Asked
Active
Viewed 1,231 times
2

bb441db
- 276
- 1
- 3
- 11
-
This might be something that you are looking for. https://stackoverflow.com/a/59177156/2014374 – bpr10 Dec 14 '20 at 13:46
1 Answers
1
EDIT/NOTE: Okay, I did some more research, as far as I know this is only a global setting on the OnePlus 6 (OxygenOs), did android P not get a dark mode after all?
So I figured out a hacky way to get this setting:
System settings are stored at: content://settings/system
On my device (OxygenOs 6.x.x) value for theme is stored at oem_black_mode
.
To fetch this result we can execute the following command via adb:
adb shell content query --uri content://settings/system/oem_black_mode
this does not require the phone to be rooted.
I have created a simple wrapper for a content resolver (feel free to use/modify):
import android.content.ContentResolver;
import android.content.Context;
import android.provider.Settings;
public class SystemSettingsResolver {
public static final String OEM_BLACK_MODE = "oem_black_mode";
public static final String OEM_BLACK_MODE_ACCENT_COLOR = "oem_black_mode_accent_color";
public static final String OEM_BLACK_MODE_ACCENT_COLOR_INDEX = "oem_black_mode_accent_color_index";
private Context context;
public SystemSettingsResolver(Context context) {
this.context = context;
}
public int getInt(String setting) {
ContentResolver resolver = context.getContentResolver();
try {
return Settings.System.getInt(resolver, setting);
} catch (Settings.SettingNotFoundException e) {
e.printStackTrace();
}
return -1;
}
public String getString(String setting) {
ContentResolver resolver = context.getContentResolver();
return Settings.System.getString(resolver, setting);
}
// extend with getFloat etc whatever is required for your app.
}
And here is how to use this wrapper:
public int systemTheme() {
/**
* In my testing:
* 0 = light
* 1 = dark
* 2 = default
*/
SystemSettingsResolver resolver = SystemSettingsResolver(this); //pass context
return resolver.getInt(SystemSettingsResolver.OEM_BLACK_MODE)
}

bb441db
- 276
- 1
- 3
- 11