我正在尝试获取dumpsys统计信息[例如dumpsys cpuinfo,dumpsys battery]。我在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" />