Android调用手电筒电源键关闭功能

释放双眼,带上耳机,听听看~!

 

frameworksbaseservicescorejavacomandroidserverpolicyPhoneWindowManager.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文章

android开发之添加随意拖动的桌面悬浮窗口

2020-2-5 13:13:19

Android文章

android开发读取sdcard路径的方法

2020-2-5 14:11:11

个人中心
购物车
优惠劵
今日签到
有新私信 私信列表
搜索