问题描述
|
我想知道这段代码中的“上下文”代表什么,我应该插入什么使其起作用? (使屏幕变暗的代码)
Settings.System.putInt(context.getContentResolver(),Settings.System.SCREEN_BRIGHTNESS,someIntValue);
解决方法
如果您是从
Activity
或Service
执行此操作:
Settings.System.putInt(this.getContentResolver(),Settings.System.SCREEN_BRIGHTNESS,someIntValue);
那是因为Activity
和Service
都继承自Context
类,并且可用作上下文值。您可以使它更加明确(仍然假设这是继承自Activity
或Service
的类):
Context context = this;
Settings.System.putInt(context.getContentResolver(),someIntValue);