搜索

9

主题

11

帖子

99

积分

注册会员

Rank: 2

积分
99
发表于 2020-8-11 20:54:16 13763 浏览 2 回复

Baterry.sevice,java 中修改开机后执行灯操作

IntentFilter filter =  new IntentFilter();
filter.addAction(Intent.ACTION_BOOT_COMPLETED);
context.registerReceiver(receiver,filter);

BroadcastReceiver receiver = new BroadcastReceiver() {
                        @Override
                        public void onReceive(Context context, Intent intent) {
                                String action = intent.getAction();
                                final int level = mHealthInfo.batteryLevel;
                final int status = mHealthInfo.batteryStatus;
                            FileWriter fw;
.......
实现开完机之后亮灯的操作。


回复

使用道具 举报

430

主题

515

帖子

2136

积分

管理员

Rank: 9Rank: 9Rank: 9

积分
2136
QQ
发表于 2020-8-11 20:56:26
你这个是啥意思?监听到开机广播之后,执行点灯操作?怎么没看到执行点灯的代码呢?
手机微信同号:13682654092
回复

使用道具 举报

9

主题

11

帖子

99

积分

注册会员

Rank: 2

积分
99
 楼主| 发表于 2020-8-21 20:52:09
tangh 发表于 2020-8-11 20:56
你这个是啥意思?监听到开机广播之后,执行点灯操作?怎么没看到执行点灯的代码呢? ...

这个是在上层的电池服务函数里面执行的充电指示灯的操作,这个APP在系统开机前就执行了点灯操作,但是必须实现在开机完成之后才能改变灯的状态。所以在这里添加一个开机广播功能,在调用那里的函数实现。以下是文件点灯函数:
import java.io.BufferedReader;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.FileReader;
import java.io.FileWriter;
import java.io.IOException;
import java.io.PrintStream;
import android.content.BroadcastReceiver;
import android.content.IntentFilter;



  try {
                             fw = new FileWriter("/sys/class/leds/red/brightness");
                              fw.write("0");
                              fw.close();
                                 fw = new FileWriter("/sys/class/leds/blue/brightness");
                              fw.write("1");
                              fw.close();
                                                         fw=newFileWriter("/sys/devices/platform/1000b000.pinctrl/mt_gpio");
                              fw.write("out 46 0");
                              fw.close();
                        } catch (IOException e) {
                                e.printStackTrace();
                        }



回复

使用道具 举报

返回列表
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则


登录或注册
快速回复 返回顶部 返回列表