3 回答

TA貢獻1878條經(jīng)驗 獲得超4個贊
使用PowerManager.WakeLock類可以執(zhí)行此操作。請參見以下代碼:
import android.os.PowerManager;
public class MyActivity extends Activity {
protected PowerManager.WakeLock mWakeLock;
/** Called when the activity is first created. */
@Override
public void onCreate(final Bundle icicle) {
setContentView(R.layout.main);
/* This code together with the one in onDestroy()
* will make the screen be always on until this Activity gets destroyed. */
final PowerManager pm = (PowerManager) getSystemService(Context.POWER_SERVICE);
this.mWakeLock = pm.newWakeLock(PowerManager.SCREEN_DIM_WAKE_LOCK, "My Tag");
this.mWakeLock.acquire();
}
@Override
public void onDestroy() {
this.mWakeLock.release();
super.onDestroy();
}
}
在清單文件中使用以下權(quán)限:
<uses-permission android:name="android.permission.WAKE_LOCK" />
希望這能解決您的問題... :)

TA貢獻1863條經(jīng)驗 獲得超2個贊
在onCreate()中的setContentView()之后添加一行代碼
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_flag);
getWindow().addFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON);
}
- 3 回答
- 0 關(guān)注
- 528 瀏覽
添加回答
舉報