0

I tried this code, but it gives me all the information in the CPU, and I just need the number of cores in the device.

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        textView = (TextView) findViewById(R.id.textView);

        byteArry = new byte[1024];

        try {
            processBuilder = new ProcessBuilder(DATA);
            process = processBuilder.start();
            inputStream = process.getInputStream();
            while (inputStream.read(byteArry) != -1); {
                Holder = Holder + new String(byteArry);
            }
            inputStream.close();

        }catch (IOException ex){
            ex.printStackTrace();
        }
        textView.setText(Holder);
    }
Bernd Wilke πφ
  • 10,390
  • 1
  • 19
  • 38

1 Answers1

0

You can try this code

 private int getNumCores() {
    class CpuFilter implements FileFilter {
        @Override
        public boolean accept(File pathname) {
            if(Pattern.matches("cpu[0-9]", pathname.getName())) {
                return true;
            }
            return false;
        }
    }

    try {
        File dir = new File("/sys/devices/system/cpu/");
        File[] files = dir.listFiles(new CpuFilter());
        Log.v( "CPU Count: ",String.valueOf(files.length));
        return files.length;
    } catch(Exception e) {
        e.printStackTrace();
        return 1;
    }
}
Emad Seliem
  • 608
  • 1
  • 4
  • 5