package com.namm.android.flashlight; import android.app.Activity; import android.os.Bundle; import android.os.PowerManager; import android.view.Window; import android.view.WindowManager; public class Flashlight extends Activity { private PowerManager.WakeLock wakeLock; /** Called when the activity is first created. */ @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); requestWindowFeature(Window.FEATURE_NO_TITLE); getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, WindowManager.LayoutParams.FLAG_FULLSCREEN); WindowManager.LayoutParams lp = getWindow().getAttributes(); lp.screenBrightness = 1; getWindow().setAttributes(lp); setContentView(R.layout.main); } @Override protected void onPause() { super.onPause(); if (wakeLock != null) { wakeLock.release(); } } @Override protected void onResume() { super.onResume(); wakeLock = ((PowerManager)getSystemService(POWER_SERVICE)). newWakeLock(PowerManager.SCREEN_BRIGHT_WAKE_LOCK | PowerManager.ON_AFTER_RELEASE, "Flashlight"); wakeLock.acquire(); } } R.java文件自动生成,这里就不提供了 AndroidManifest.xml: <?xml version="1.0" encoding="utf-8"?> <manifest xmlns:android="http://schemas.android.com/apk/res/android" package="com.namm.android.flashlight" android:versionCode="1" android:versionName="1.0"> <application android:icon="@drawable/icon" android:label="@string/app_name"> <activity android:name=".Flashlight" android:label="@string/app_name"> <intent-filter> <action android:name="android.intent.action.MAIN" /> <category android:name="android.intent.category.LAUNCHER" /> </intent-filter> </activity> </application> <uses-sdk android:minSdkVersion="4" /> <uses-permission android:name="android.permission.WAKE_LOCK" /> </manifest> layout/main.xml: <?xml version="1.0" encoding="utf-8"?> <manifest xmlns:android="http://schemas.android.com/apk/res/android" package="com.namm.android.flashlight" android:versionCode="1" android:versionName="1.0"> <application android:icon="@drawable/icon" android:label="@string/app_name"> <activity android:name=".Flashlight" android:label="@string/app_name"> <intent-filter> <action android:name="android.intent.action.MAIN" /> <category android:name="android.intent.category.LAUNCHER" /> </intent-filter> </activity> </application> <uses-sdk android:minSdkVersion="4" /> <uses-permission android:name="android.permission.WAKE_LOCK" /> </manifest> values/strings.xml: <?xml version="1.0" encoding="utf-8"?> <resources> <string name="app_name">Flashlight</string> </resources>