一開始接觸android應用項目時,在項目快上線時策劃要求加個高亮,每次都是直接從網上百度一下,如今作遊戲了,卻仍是這個需求,這裏備份一下方便後續的查找,畢竟是本身寫好且驗證沒問題的 :)java
首先,在Activity裏添加一下代碼:android
成員變量: private PowerManager.WakeLock wakeLock = null; 重寫父類Activity的兩個方法並添加一下邏輯: @Override public void onResume() { super.onResume(); acquireWakeLock(this); } @Override public void onPause() { super.onPause(); releaseWakeLock(); } public void acquireWakeLock(Context context) { if (wakeLock == null) { PowerManager powerManager = (PowerManager) (context .getSystemService(Context.POWER_SERVICE)); wakeLock = powerManager.newWakeLock( PowerManager.SCREEN_DIM_WAKE_LOCK, "My Tag"); wakeLock.acquire(); } } public void releaseWakeLock() { if (wakeLock != null && wakeLock.isHeld()) { wakeLock.release(); wakeLock = null; } }
而後,在AndroidManifest.xml裏添加以下權限便可:ide
<uses-permission android:name="android.permission.WAKE_LOCK" />
2016-04-14ui
IOS設備下的屏幕常亮處理:this
在AppController.mm文件的didFinishLaunchingWithOptions方法裏面,添加code
[ [ UIApplication sharedApplication ] setIdleTimerDisabled:YES ] ;到xml
[[UIApplication sharedApplication] setStatusBarHidden: YES];這句代碼後面。遊戲