在打开手电筒之后 机器休眠 客户要求点击电源键 手电筒需要关闭
frameworksaseservicescorejavacomandroidserverpolicyPhoneWindowManager.java
@Override
public void screenTurnedOn() {
synchronized (mLock) {
if (mKeyguardDelegate != null) {
mKeyguardDelegate.onScreenTurnedOn();
}
if (SystemProperties.getInt("persist.sys.screen_first_on", 1) == 0) {
android.util.Log.d("chch", "turnOffFlashLightIfNeed");
turnOffFlashLightIfNeed();
}else{
SystemProperties.set("persist.sys.screen_first_on", "0");
}
}
}
private void turnOffFlashLightIfNeed(){
try{
mCameraManager = (CameraManager) mContext.getSystemService(Context.CAMERA_SERVICE);
mCameraId = mCameraManager.getCameraIdList()[0];
mCameraManager.setTorchMode(mCameraId,false);
}catch(Exception e){
android.util.Log.d("chch", "camera error");
}
}
前面要增加
import android.hardware.camera2.CameraManager;
增加变量
CameraManager mCameraManager;
String mCameraId;