Android实现手电筒电源键关闭功能
时间:2020-10-06 21:54:43|栏目:Android代码|点击: 次
在打开手电筒之后 机器休眠 客户要求点击电源键 手电筒需要关闭
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;
总结
上一篇:百度语音识别(Baidu Voice) Android studio版本详解
栏 目:Android代码
本文标题:Android实现手电筒电源键关闭功能
本文地址:http://www.codeinn.net/misctech/7672.html