android:
在proj.android\src\org\cocos2dx\enshi\wxapi\WXEntryActivity.java目录下修改:
主要修改的地方有:
private PowerManager powerManager = null;
private WakeLock wakeLock = null;
powerManager = (PowerManager) this.getSystemService(Service.POWER_SERVICE);
wakeLock = this.powerManager.newWakeLock(PowerManager.SCREEN_DIM_WAKE_LOCK,"My Lock");
onResume()方法这3个地方。。。
package org.cocos2dx.enshi.wxapi;
import org.cocos2dx.enshi.R;
import android.app.Service;
import android.content.Context;
import android.content.Intent;
import android.content.SharedPreferences;
import android.os.Bundle;
import android.os.Handler;
import android.os.PowerManager;
import android.os.PowerManager.WakeLock;
import android.util.Log;
import org.cocos2dx.lua.AppActivity;
public class WXEntryActivity extends AppActivity implements IWXAPIEventHandler {
private static WXEntryActivity instance = null;
private static Handler mloginHandler = null;
private static Handler mShareUrlHandler = null;
private PowerManager powerManager = null;
private WakeLock wakeLock = null;
// IWXAPI 是第三方app和微信通信的openapi接口
public static IWXAPI api;
public static WXEntryActivity getInstance() {
if (instance == null) {
instance = new WXEntryActivity();
}
return instance;
}
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
powerManager = (PowerManager) this.getSystemService(Service.POWER_SERVICE);
wakeLock = this.powerManager.newWakeLock(PowerManager.SCREEN_DIM_WAKE_LOCK,"My Lock");
//是否需计算锁的数量
wakeLock.setReferenceCounted(false);
if (instance == null) {
new BaseSdk(this,0);
this.initsdk();
}
instance = this;
}
@Override
protected void onResume()
{
super.onResume();
wakeLock.acquire();
}
其次在AndroidManifest.xml中添加常亮权限:
<!--屏幕常量-->
<uses-permission android:name="android.permission.WAKE_LOCK" />
IOS:
在frameworks\runtime-src\proj.ios_mac\ios\AppController.mm目录下:
在AppController.mm文件的didFinishLaunchingWithOptions方法里面,
[[UIApplicationsharedApplication]setStatusBarHidden:YES];这句后面添加:
//屏幕常亮 [[UIApplication sharedApplication] setIdleTimerDisabled:YES];至此结束!!!