android 手电筒电源键关闭功能实现

2019-07-14 03:37发布

在打开手电筒之后 机器休眠 客户要求点击电源键 手电筒需要关闭
frameworksaseservicescorejavacomandroidserverpolicyPhoneWindowManager.java @Override public void screenTurnedOn() { synchronized (mLock) { if (mKeyguardDelegate != null) { mKeyguardDelegate.onScreenTurnedOn(); } //add start 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"); } //end } } //chch add start 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"); } } //chch end 前面要增加
import android.hardware.camera2.CameraManager;
增加变量
CameraManager mCameraManager;
String mCameraId;