سؤال

In my app, when a button is clicked, I would like to call the Brightness class found in Android system settings (shown when the user navigates Settings > Display > Brightness).

I know that to call the Display class (on which the Brightness class is found) I can use the following code:

Intent brightness = new Intent();
brightness.setClassName("com.android.settings", "com.android.settings.DisplaySettings");
startActivity(brightness);

So, it would seem intuitive that to call the Brightness class, one would substitute "BrightnessPreference" for "DisplaySettings" (since both are saved in the same location as seen at this link) as follows:

Intent brightness = new Intent();
brightness.setClassName("com.android.settings", "com.android.settings.BrightnessPreference");
startActivity(brightness);

However, when I try to run this code on my emulator, it force closes. Is there anything I'm not seeing, or is calling BrightnessPreference not possible for some reason?

هل كانت مفيدة؟

المحلول

BrightnessPreference extends Preference Class.

According to the docs

Preference class provides the View to be displayed in the activity

Where as what you are trying to do is open it as an activity using an intent, which according me is not possible.

You can set it programmatically as shown here

مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top