Android上层怎样读写proc节点(示例)
发布日期:2021-06-30 18:52:33
浏览次数:3
分类:技术文章
本文共 1691 字,大约阅读时间需要 5 分钟。
import android.app.Activity; import android.os.Bundle; import android.widget.CompoundButton; import android.widget.CompoundButton.OnCheckedChangeListener; import android.widget.ToggleButton; import android.os.SystemProperties; import android.util.Log; import android.widget.Toast; //wang import java.util.Timer; import java.util.TimerTask; import android.os.PowerManager; import java.io.*; import android.os.Looper; public class DebugOptionActivity extends Activity { private static final String TAG = "tpDebug"; private int checkValue = 0; @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.debug); ToggleButton toggle = (ToggleButton)findViewById(R.id.toggle); try{ File readFile = new File("proc/tp_debug/debug_switch"); FileReader inCmd = new FileReader(readFile); try{ checkValue = inCmd.read(); if(checkValue != 0) { toggle.setChecked(true); } else { toggle.setChecked(false); } }catch (IOException e){ e.printStackTrace(); } } catch (FileNotFoundException e){ e.printStackTrace(); } //ToggleButton toggle = (ToggleButton)findViewById(R.id.toggle); toggle.setOnCheckedChangeListener(new OnCheckedChangeListener() { public void onCheckedChanged(CompoundButton arg0, boolean arg1) { if (arg1) { //open File awakeTimeFile = new File("proc/tp_debug/debug_switch"); FileWriter fr; try { fr = new FileWriter(awakeTimeFile); fr.write("1"); fr.close(); } catch (IOException e) { e.printStackTrace(); } } else { //close File awakeTimeFile = new File("proc/tp_debug/debug_switch"); FileWriter fr; try { fr = new FileWriter(awakeTimeFile); fr.write("0"); fr.close(); } catch (IOException e) { e.printStackTrace(); } } } }); } }转载地址:https://linus.blog.csdn.net/article/details/42239285 如侵犯您的版权,请留言回复原文章的地址,我们会给您删除此文章,给您带来不便请您谅解!
发表评论
最新留言
留言是一种美德,欢迎回访!
[***.207.175.100]2024年04月27日 12时16分37秒
关于作者
喝酒易醉,品茶养心,人生如梦,品茶悟道,何以解忧?唯有杜康!
-- 愿君每日到此一游!
推荐文章
YAPF —— Python代码格式化工具
2019-04-30
UGC 用户产生内容
2019-04-30
ranger
2019-04-30
slurm
2019-04-30
xfce4
2019-04-30
xrdp
2019-04-30
Raft算法
2019-04-30
Python计算文本BLEU分数
2019-04-30
swap内存(linux)
2019-04-30
人脸au
2019-04-30
torch.distributed 分布式
2019-04-30
PyPy
2019-04-30
MATLAB与CUDA
2019-04-30
Linux png转jpg (convert命令)
2019-04-30
NAS (Network Attached Storage 网络附属存储)
2019-04-30
Ubuntu更新后终端中字体的颜色全是白色
2019-04-30
Ninja
2019-04-30
vscode git
2019-04-30
基于MATLAB的二进制数字调制与解调信号的仿真——2FSK
2019-04-30
基于MATLAB的二进制数字调制与解调信号的仿真——2PSK
2019-04-30