在打开手电筒之后 机器休眠 客户要求点击电源键 手电筒需要关闭
frameworks\base\services\core\java\com\android\server\policy\PhoneWindowManager.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;
总结
以上所述是小编给大家介绍的Android实现手电筒电源键关闭功能,希望对大家有所帮助,如果大家有任何疑问请给我留言,小编会及时回复大家的。在此也非常感谢大家对脚本之家网站的支持!