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) {

}

}

}

}

//*/

相关推荐
ANYOUZHEN4 小时前
bugku shell
android
南宫码农7 小时前
我的电视 - Android原生电视直播软件 完整使用教程
android·开发语言·windows·电视盒子
道亦无名8 小时前
音频数据特征值提取 方法和步骤
android·音视频
Lancker8 小时前
定制侠 一个国产纯血鸿蒙APP的诞生过程
android·华为·智能手机·鸿蒙·国产操作系统·纯血鸿蒙·华为鸿蒙
2601_949809599 小时前
flutter_for_openharmony家庭相册app实战+通知设置实现
android·javascript·flutter
液态不合群10 小时前
【面试题】MySQL 中 count(*)、count(1) 和 count(字段名) 有什么区别?
android·数据库·mysql
雪球Snowball12 小时前
【Android关键流程】资源加载
android
2501_9159184112 小时前
常见 iOS 抓包工具的使用,从代理抓包、设备抓包到数据流抓包
android·ios·小程序·https·uni-app·iphone·webview
墨月白13 小时前
[QT]QProcess的相关使用
android·开发语言·qt
enbug14 小时前
编译安卓内核:以坚果R1、魔趣MK100(Android 10)系统为例
android·linux