codereviewanskquestions
codereviewanskquestions

Reputation: 13998

How do I read proc/stat from android device?

I am trying to create a cpu usage monitoring application and I was wondering how I can read proc/stat from Android application.

Thanks in advance..

Upvotes: 0

Views: 4003

Answers (1)

Matthieu
Matthieu

Reputation: 16397

Just read it like any other file...

try {
    BufferedReader mounts = new BufferedReader(new FileReader("/proc/stat"));
    String line;

    while ((line = mounts.readLine()) != null) {
        // do some processing here
    }
}
catch (FileNotFoundException e) {
    Log.d(TAG, "Cannot find /proc/stat...");
}
catch (IOException e) {
    Log.d(TAG, "Ran into problems reading /proc/stat...");
}

Upvotes: 3

Related Questions