Android 按两下power键不打开相机改为打开手电筒

MTK平台默认按两下power键打开相机的快捷手势,如今需求改为快捷打开手电筒,需要找到位置进行替换即可,写入节点,加入节点权限。

/frameworks/base/services/core/java/com/android/server/GestureLauncherService.java

//*/add pkg
import java.io.File;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.OutputStreamWriter;
import java.io.Writer;
import android.util.Log;
//*/

//*/add global variable opne flashlight to switch on/off
private boolean mFlashlight = false;
//*/

if (launchCamera) {//两下power键打开相机
/*/add,repalce double open camera with open flashlight
launchCamera = handleCameraGesture(false ,
StatusBarManager.CAMERA_LAUNCH_SOURCE_POWER_DOUBLE_TAP);//1 // useWakelock
/*/
mFlashlight = !mFlashlight;
writeFlashLightFile(mFlashlight);
//*/
if (launchCamera) {
mMetricsLogger.action(MetricsEvent.ACTION_DOUBLE_TAP_POWER_CAMERA_GESTURE,
(int) powerTapInterval);
mUiEventLogger.log(GestureLauncherEvent.GESTURE_CAMERA_DOUBLE_TAP_POWER);
}
} else if (launchEmergencyGesture) {//五下power键打开紧急拨号
Slog.i(TAG, "Emergency gesture detected, launching.");
launchEmergencyGesture = handleEmergencyGesture();
mUiEventLogger.log(GestureLauncherEvent.GESTURE_EMERGENCY_TAP_POWER);
}

//*/add open flash method

private static void writeFlashLightFile (boolean enable) {

File file = new File("/sys/kernel/flash_cur/flash_cur");

Writer writer = null;

try {

writer = new OutputStreamWriter(new FileOutputStream(file));

if (enable) {

writer.append("1");

} else {

writer.append("0");

}

} catch (FileNotFoundException e) {

} catch (IOException e) {

} finally {

if (writer != null) {

try {

writer.close();

} catch (IOException e) {

}

}

}

}

//*/

相关推荐
susu10830189112 分钟前
Android Studio打包APK
android·ide·android studio
2401_8979078633 分钟前
Android 存储进化:分区存储
android
Dwyane037 小时前
Android实战经验篇-AndroidScrcpyClient投屏一
android
FlyingWDX8 小时前
Android 拖转改变视图高度
android
_可乐无糖8 小时前
Appium 检查安装的驱动
android·ui·ios·appium·自动化
一名技术极客10 小时前
Python 进阶 - Excel 基本操作
android·python·excel
我是大佬的大佬10 小时前
在Android Studio中如何实现综合实验MP3播放器(保姆级教程)
android·ide·android studio
lichong95110 小时前
【Flutter&Dart】MVVM(Model-View-ViewModel)架构模式例子-http版本(30 /100)
android·flutter·http·架构·postman·win·smartapi
刘争Stanley11 小时前
Android系统开发(六):从Linux到Android:模块化开发,GKI内核的硬核科普
android·linux·运维·内核·镜像·gki·kmi
五味香11 小时前
Java学习,List截取
android·java·开发语言·python·学习·golang·kotlin