我正在尝试获取 dumpsys 统计信息 [如 dumpsys cpuinfo、dumpsys 电池]。我在java中执行这些并将其写入文件。但我得到,
2012.06.20 07:32:19
Permission Denial: can't dump cpuinfo from from pid=862, uid=10040 without permission android.permission.DUMP
for all dumpsys commands.
我已经在 android.manifest"android.permission.DUMP"
中添加了权限。"android.permission.BATTERY_STATS"
但是,没有得到结果请帮助作为它的关键。我使用的代码如下,其中 cmd 包含 dumpsys cpuinfo 或 dumpsys battery [任何人]
Calendar cal = Calendar.getInstance();
SimpleDateFormat sdf = new SimpleDateFormat("yyyy.MM.dd HH:mm:ss");
System.setOut(new PrintStream(new FileOutputStream("/sdcard/Monitor/"+file+".txt",false)));
System.out.println("\n\n"+sdf.format(cal.getTime()));
Log.w("cmd-fn", cmd);
process=Runtime.getRuntime().exec(cmd);
process.waitFor();
BufferedReader bufferedReader = new BufferedReader(new InputStreamReader(process.getInputStream()));
String buffer="";
while((buffer=bufferedReader.readLine())!=null)
{
//fileobj.write(buffer);
System.out.println(buffer);
//output.write(buffer);
}
buffer="";
BufferedReader buffered = new BufferedReader(new InputStreamReader(process.getErrorStream()));
while((buffer=buffered.readLine())!=null)
{
Log.w("exception",buffer);
}
以下是我的清单条目
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/>
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.DUMP" />
<uses-permission android:name="android.permission.BATTERY_STATS" />
<uses-permission android:name="android.permission.READ_PHONE_STATE" />