使用上下文使屏幕变暗

| 我想知道这段代码中的“上下文”代表什么,我应该插入什么使其起作用? (使屏幕变暗的代码)
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(), Settings.System.SCREEN_BRIGHTNESS, someIntValue);
    

要回复问题请先登录注册