Tom*_*Tom 11 java android android-1.5-cupcake
我知道可以使用唤醒锁来保持屏幕,cpu等,但我怎样才能以编程方式更改Android手机上的" 屏幕超时 "设置.
小智 27
public class HelloWorld extends Activity
{
private static final int DELAY = 3000;
int defTimeOut = 0;
@Override
protected void onCreate(Bundle savedInstanceState)
{
// Be sure to call the super class.
super.onCreate(savedInstanceState);
// See assets/res/any/layout/hello_world.xml for this
// view layout definition, which is being set here as
// the content of our screen.
setContentView(R.layout.hello_world);
defTimeOut = Settings.System.getInt(getContentResolver(),
Settings.System.SCREEN_OFF_TIMEOUT, DELAY);
Settings.System.putInt(getContentResolver(), Settings.System.SCREEN_OFF_TIMEOUT, DELAY);
}
@Override
protected void onDestroy()
{
super.onDestroy();
Settings.System.putInt(getContentResolver(), Settings.System.SCREEN_OFF_TIMEOUT, defTimeOut);
}
}
Run Code Online (Sandbox Code Playgroud)
并且也不要忘记在清单中添加此权限:
android:name="android.permission.WRITE_SETTINGS"
Run Code Online (Sandbox Code Playgroud)
小智 14
以上是正确的:
Settings.System.putInt(getContentResolver(),Settings.System.SCREEN_OFF_TIMEOUT, DELAY);
Run Code Online (Sandbox Code Playgroud)
但也包括清单中的权限:
android:name="android.permission.WRITE_SETTINGS"
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
22550 次 |
| 最近记录: |