문제

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