Android上层读写器节点(实例)
import android.app.Activity;
import android.os.Bundle;
import android. widget.CompoundButton;
导入 android.widget.CompoundButton.OnCheckedChangeListener;
导入 android.widget.ToggleButton;
导入 android.os.SystemProperties;
导入 android.widget.ToggleButton;
导入 android.os.SystemProperties;
p>
导入 android.util.Log;
导入 android.widget.Toast; //wang
导入java.util.Timer;
导入java.util.TimerTask;
导入android.os.PowerManager;
< p>导入java.io.*;导入 android.os.Looper;
公共类 DebugOptionActivity 扩展 Activity
{
私有静态最终字符串 TAG = "tpDebug" ;
private int checkValue = 0;
@Override
public void onCreate(Bundle savingInstanceState)
{
< p>super.onCreate(savedInstanceState);setContentView(R.layout.debug);
ToggleButton 切换 = (ToggleButton)findViewById(R.id.toggle);
尝试{
File readFile = new File("proc/tp_debug/debug_switch");
FileReader inCmd = new FileReader(readFile);
尝试{
checkValue = inCmd.read();
if(checkValue != 0)
{
toggle.setChecked (true);
}
其他
{
toggle.setChecked(false);
}
}catch (IOException e){
e.printStackTrace();
}
} catch (FileNotFoundException e){< /p>
e.printStackTrace();
}
//ToggleButton 切换 = (ToggleButton)findViewById(R.id.toggle);
toggle.setOnCheckedCh
angeListener(new OnCheckedChangeListener()
{
public void onCheckedChanged(CompoundButton arg0, boolean arg1)
{
if (arg1)
{
//打开
File awakeTimeFile = new File("proc/tp_debug/debug_switch");
FileWriter fr;
尝试 {
fr = new FileWriter(awakeTimeFile);
fr.write("1");
fr.close ();
}
catch (IOException e) {
e.printStackTrace();
}
< p>}else
{
//关闭
File awakeTimeFile = new File("proc/tp_debug/debug_switch") ;
FileWriter fr;
尝试
{
fr = new FileWriter(awakeTimeFile);
fr .write("0");
fr.close();
} catch (IOException e) {
e.printStackTrace(); p>
}
}
}
});
}
} p>