get Cpu Info - Android Hardware

Android examples for Hardware:CPU Information

Description

get Cpu Info

Demo Code


//package com.java2s;

import android.text.TextUtils;

import java.io.BufferedReader;
import java.io.FileReader;
import java.io.IOException;

public class Main {

    public static String getCpuInfo() {
        String str1 = "/proc/cpuinfo";
        String str2 = "";
        String cpuInfo = "";
        String[] arrayOfString = null;
        try {//from  w  w  w. j a va 2 s  .co m
            FileReader fr = new FileReader(str1);
            BufferedReader localBufferedReader = new BufferedReader(fr,
                    8192);
            str2 = localBufferedReader.readLine();
            if (!TextUtils.isEmpty(str2)) {
                arrayOfString = str2.split("\\s+");
                for (int i = 2; i < arrayOfString.length; i++) {
                    cpuInfo = cpuInfo + arrayOfString[i] + " ";
                }
            }
            localBufferedReader.close();
        } catch (IOException e) {
            return cpuInfo;
        }
        return cpuInfo;
    }
}

Related Tutorials