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 如侵犯您的版权,请留言回复原文章的地址,我们会给您删除此文章,给您带来不便请您谅解!

上一篇:Android kernel Crash后,定位出错点的方法
下一篇:怎样在Linux驱动中创建proc节点(示例)

发表评论

最新留言

留言是一种美德,欢迎回访!
[***.207.175.100]2024年04月27日 12时16分37秒

关于作者

    喝酒易醉,品茶养心,人生如梦,品茶悟道,何以解忧?唯有杜康!
-- 愿君每日到此一游!

推荐文章