- 前言
记录下cocos2dx手机游戏时不自动锁屏的相关配置。
IOS上屏蔽锁屏配置
1,找到工程..\frameworks\runtime-src\proj.ios_mac\ios路径下的AppController.mm这个文件。
2,加入下面这行代码
[[UIApplication sharedApplication] setIdleTimerDisabled: YES];
Android上屏蔽锁屏配置
1,找到工程下这个文件
2,修改下面这几处
代码如下:
//1
@H_502_34@import android.os.PowerManager;
//2
PowerManager.WakeLock mWakeLock;
//3
PowerManager pm = (PowerManager) getSystemService(Context.POWER_SERVICE);
mWakeLock = pm.newWakeLock(PowerManager.SCREEN_BRIGHT_WAKE_LOCK,"XYTEST");
mWakeLock.acquire();
//4
@H_502_34@public @H_502_34@void onDestroy()
{
@H_502_34@super.onDestroy();
@H_502_34@if(mWakeLock == @H_502_34@null) {
mWakeLock.release();
}
}
@H_502_34@public @H_502_34@void onPause()
{
@H_502_34@super.onPause();
@H_502_34@if(mWakeLock != @H_502_34@null)
{
mWakeLock.release();
mWakeLock = @H_502_34@null;
}
}
@H_502_34@public @H_502_34@void onResume()
{
@H_502_34@super.onResume();
@H_502_34@if(mWakeLock == @H_502_34@null)
{
PowerManager pm = (PowerManager)getSystemService(Context.POWER_SERVICE);
mWakeLock = pm.newWakeLock(PowerManager.SCREEN_BRIGHT_WAKE_LOCK,"XYTEST");
mWakeLock.acquire();
}
}
3,找到..\frameworks\runtime-src\proj.android路径下的AndroidManifest.xml文件,加入下面这行代码:
<uses-permission android:name="android.permission.WAKE_LOCK"/>
如图:
OK!