How can you detect a dual-core cpu on an Android device from code?










20















I've run into a problem that appears to effect only dual-core Android devices running gingerbread or greater. I'd like to give a dialog regarding this issue only to my users that fit that criteria. I know how to check OS level, but haven't found anything that can definitively tell me the device is using multi-core.



Any ideas?










share|improve this question




























    20















    I've run into a problem that appears to effect only dual-core Android devices running gingerbread or greater. I'd like to give a dialog regarding this issue only to my users that fit that criteria. I know how to check OS level, but haven't found anything that can definitively tell me the device is using multi-core.



    Any ideas?










    share|improve this question


























      20












      20








      20


      17






      I've run into a problem that appears to effect only dual-core Android devices running gingerbread or greater. I'd like to give a dialog regarding this issue only to my users that fit that criteria. I know how to check OS level, but haven't found anything that can definitively tell me the device is using multi-core.



      Any ideas?










      share|improve this question
















      I've run into a problem that appears to effect only dual-core Android devices running gingerbread or greater. I'd like to give a dialog regarding this issue only to my users that fit that criteria. I know how to check OS level, but haven't found anything that can definitively tell me the device is using multi-core.



      Any ideas?







      android






      share|improve this question















      share|improve this question













      share|improve this question




      share|improve this question








      edited Aug 6 '15 at 21:06







      newbyca

















      asked Nov 1 '11 at 3:27









      newbycanewbyca

      1,25821124




      1,25821124






















          5 Answers
          5






          active

          oldest

          votes


















          41














          Unfortunately for most Android devices, the availableProcessors() method doesn't work correctly. Even /proc/stat doesn't always show the correct number of CPUs.



          The only reliable method I've found to determine the number of CPUs is to enumerate the list of virtual CPUs at /sys/devices/system/cpu/ as described in this forum post. The code:



          /**
          * Gets the number of cores available in this device, across all processors.
          * Requires: Ability to peruse the filesystem at "/sys/devices/system/cpu"
          * @return The number of cores, or 1 if failed to get result
          */
          private int getNumCores()
          //Private Class to display only CPU devices in the directory listing
          class CpuFilter implements FileFilter
          @Override
          public boolean accept(File pathname)
          //Check if filename is "cpu", followed by one or more digits
          if(Pattern.matches("cpu[0-9]+", pathname.getName()))
          return true;

          return false;



          try
          //Get directory containing CPU info
          File dir = new File("/sys/devices/system/cpu/");
          //Filter to only list the devices we care about
          File files = dir.listFiles(new CpuFilter());
          //Return the number of cores (virtual CPU devices)
          return files.length;
          catch(Exception e)
          //Default to return 1 core
          return 1;




          This Java code should work in any Android application, even without root.






          share|improve this answer




















          • 1





            the link you've provided is dead . also, i have some questions: it doesn't require any permission, right? also, will it even work when there are more than 9 cores?

            – android developer
            Jul 16 '13 at 7:53












          • Thanks, fixed the link. You shouldn't need any special permissions to run this code (although it could change in later Android versions). If you need to support devices with more than 10 cores, the regexp should look like this: "cpu[0-9]+" (note the extra plus sign). I'll update the post to match.

            – David
            Jul 21 '13 at 12:19











          • thank you for your help.

            – android developer
            Jul 21 '13 at 12:28






          • 1





            4 on Samsung Tab 3, but should return 2

            – Suvitruf
            Dec 15 '13 at 21:19











          • Perhaps it's a hyperthreaded Dual Core processor? This would appear as 4 processors to the system.

            – David
            Jan 2 '14 at 22:59


















          8














          If you're working with a native application, you should try this:



          #include <unistd.h>
          int GetNumberOfProcessor()

          return sysconf(_SC_NPROCESSORS_CONF);



          It work on my i9100 (which availableProcessors() returned 1).






          share|improve this answer






























            4














            You can try using Runtime.availableProcessors() as is suggested in this answer



            Is there any API that tells whether an Android device is dual-core or not?



            ---edit---



            A more detailed description is given at Oracle's site




            availableProcessors



            public int availableProcessors()


            Returns the number of processors available to the Java virtual machine.



            This value may change during a particular invocation of the virtual machine. Applications that are sensitive to the number of available processors should therefore occasionally poll this property and adjust their resource usage appropriately.



            Returns:



            the maximum number of processors available to the virtual machine; never smaller than one



            Since:



             1.4






            share|improve this answer

























            • Awesome Thanks! I hadn't seen that. Just a note: on my Motorola Droid X2 availableProcessors() returns "1" ... when it should return a 2. on a Xoom availableProcessors() correctly returns 2. any other ways?

              – newbyca
              Nov 1 '11 at 4:44


















            4














            This is pretty simple.



            int numberOfProcessors = Runtime.getRuntime().availableProcessors();


            Typically it would return 1 or 2. 2 would be in a dual-core CPU.






            share|improve this answer


















            • 2





              Here is an example of using availableProcessprs() to determine the size of pool thread.

              – bachr
              Jun 28 '14 at 10:14



















            0














            I use a combination of both available solutions:



            fun getCPUCoreNum(): Int 
            val pattern = Pattern.compile("cpu[0-9]+")
            return Math.max(
            File("/sys/devices/system/cpu/")
            .walk()
            .maxDepth(1)
            .count pattern.matcher(it.name).matches() ,
            Runtime.getRuntime().availableProcessors()
            )






            share|improve this answer
























              Your Answer






              StackExchange.ifUsing("editor", function ()
              StackExchange.using("externalEditor", function ()
              StackExchange.using("snippets", function ()
              StackExchange.snippets.init();
              );
              );
              , "code-snippets");

              StackExchange.ready(function()
              var channelOptions =
              tags: "".split(" "),
              id: "1"
              ;
              initTagRenderer("".split(" "), "".split(" "), channelOptions);

              StackExchange.using("externalEditor", function()
              // Have to fire editor after snippets, if snippets enabled
              if (StackExchange.settings.snippets.snippetsEnabled)
              StackExchange.using("snippets", function()
              createEditor();
              );

              else
              createEditor();

              );

              function createEditor()
              StackExchange.prepareEditor(
              heartbeatType: 'answer',
              autoActivateHeartbeat: false,
              convertImagesToLinks: true,
              noModals: true,
              showLowRepImageUploadWarning: true,
              reputationToPostImages: 10,
              bindNavPrevention: true,
              postfix: "",
              imageUploader:
              brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
              contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
              allowUrls: true
              ,
              onDemand: true,
              discardSelector: ".discard-answer"
              ,immediatelyShowMarkdownHelp:true
              );



              );













              draft saved

              draft discarded


















              StackExchange.ready(
              function ()
              StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f7962155%2fhow-can-you-detect-a-dual-core-cpu-on-an-android-device-from-code%23new-answer', 'question_page');

              );

              Post as a guest















              Required, but never shown

























              5 Answers
              5






              active

              oldest

              votes








              5 Answers
              5






              active

              oldest

              votes









              active

              oldest

              votes






              active

              oldest

              votes









              41














              Unfortunately for most Android devices, the availableProcessors() method doesn't work correctly. Even /proc/stat doesn't always show the correct number of CPUs.



              The only reliable method I've found to determine the number of CPUs is to enumerate the list of virtual CPUs at /sys/devices/system/cpu/ as described in this forum post. The code:



              /**
              * Gets the number of cores available in this device, across all processors.
              * Requires: Ability to peruse the filesystem at "/sys/devices/system/cpu"
              * @return The number of cores, or 1 if failed to get result
              */
              private int getNumCores()
              //Private Class to display only CPU devices in the directory listing
              class CpuFilter implements FileFilter
              @Override
              public boolean accept(File pathname)
              //Check if filename is "cpu", followed by one or more digits
              if(Pattern.matches("cpu[0-9]+", pathname.getName()))
              return true;

              return false;



              try
              //Get directory containing CPU info
              File dir = new File("/sys/devices/system/cpu/");
              //Filter to only list the devices we care about
              File files = dir.listFiles(new CpuFilter());
              //Return the number of cores (virtual CPU devices)
              return files.length;
              catch(Exception e)
              //Default to return 1 core
              return 1;




              This Java code should work in any Android application, even without root.






              share|improve this answer




















              • 1





                the link you've provided is dead . also, i have some questions: it doesn't require any permission, right? also, will it even work when there are more than 9 cores?

                – android developer
                Jul 16 '13 at 7:53












              • Thanks, fixed the link. You shouldn't need any special permissions to run this code (although it could change in later Android versions). If you need to support devices with more than 10 cores, the regexp should look like this: "cpu[0-9]+" (note the extra plus sign). I'll update the post to match.

                – David
                Jul 21 '13 at 12:19











              • thank you for your help.

                – android developer
                Jul 21 '13 at 12:28






              • 1





                4 on Samsung Tab 3, but should return 2

                – Suvitruf
                Dec 15 '13 at 21:19











              • Perhaps it's a hyperthreaded Dual Core processor? This would appear as 4 processors to the system.

                – David
                Jan 2 '14 at 22:59















              41














              Unfortunately for most Android devices, the availableProcessors() method doesn't work correctly. Even /proc/stat doesn't always show the correct number of CPUs.



              The only reliable method I've found to determine the number of CPUs is to enumerate the list of virtual CPUs at /sys/devices/system/cpu/ as described in this forum post. The code:



              /**
              * Gets the number of cores available in this device, across all processors.
              * Requires: Ability to peruse the filesystem at "/sys/devices/system/cpu"
              * @return The number of cores, or 1 if failed to get result
              */
              private int getNumCores()
              //Private Class to display only CPU devices in the directory listing
              class CpuFilter implements FileFilter
              @Override
              public boolean accept(File pathname)
              //Check if filename is "cpu", followed by one or more digits
              if(Pattern.matches("cpu[0-9]+", pathname.getName()))
              return true;

              return false;



              try
              //Get directory containing CPU info
              File dir = new File("/sys/devices/system/cpu/");
              //Filter to only list the devices we care about
              File files = dir.listFiles(new CpuFilter());
              //Return the number of cores (virtual CPU devices)
              return files.length;
              catch(Exception e)
              //Default to return 1 core
              return 1;




              This Java code should work in any Android application, even without root.






              share|improve this answer




















              • 1





                the link you've provided is dead . also, i have some questions: it doesn't require any permission, right? also, will it even work when there are more than 9 cores?

                – android developer
                Jul 16 '13 at 7:53












              • Thanks, fixed the link. You shouldn't need any special permissions to run this code (although it could change in later Android versions). If you need to support devices with more than 10 cores, the regexp should look like this: "cpu[0-9]+" (note the extra plus sign). I'll update the post to match.

                – David
                Jul 21 '13 at 12:19











              • thank you for your help.

                – android developer
                Jul 21 '13 at 12:28






              • 1





                4 on Samsung Tab 3, but should return 2

                – Suvitruf
                Dec 15 '13 at 21:19











              • Perhaps it's a hyperthreaded Dual Core processor? This would appear as 4 processors to the system.

                – David
                Jan 2 '14 at 22:59













              41












              41








              41







              Unfortunately for most Android devices, the availableProcessors() method doesn't work correctly. Even /proc/stat doesn't always show the correct number of CPUs.



              The only reliable method I've found to determine the number of CPUs is to enumerate the list of virtual CPUs at /sys/devices/system/cpu/ as described in this forum post. The code:



              /**
              * Gets the number of cores available in this device, across all processors.
              * Requires: Ability to peruse the filesystem at "/sys/devices/system/cpu"
              * @return The number of cores, or 1 if failed to get result
              */
              private int getNumCores()
              //Private Class to display only CPU devices in the directory listing
              class CpuFilter implements FileFilter
              @Override
              public boolean accept(File pathname)
              //Check if filename is "cpu", followed by one or more digits
              if(Pattern.matches("cpu[0-9]+", pathname.getName()))
              return true;

              return false;



              try
              //Get directory containing CPU info
              File dir = new File("/sys/devices/system/cpu/");
              //Filter to only list the devices we care about
              File files = dir.listFiles(new CpuFilter());
              //Return the number of cores (virtual CPU devices)
              return files.length;
              catch(Exception e)
              //Default to return 1 core
              return 1;




              This Java code should work in any Android application, even without root.






              share|improve this answer















              Unfortunately for most Android devices, the availableProcessors() method doesn't work correctly. Even /proc/stat doesn't always show the correct number of CPUs.



              The only reliable method I've found to determine the number of CPUs is to enumerate the list of virtual CPUs at /sys/devices/system/cpu/ as described in this forum post. The code:



              /**
              * Gets the number of cores available in this device, across all processors.
              * Requires: Ability to peruse the filesystem at "/sys/devices/system/cpu"
              * @return The number of cores, or 1 if failed to get result
              */
              private int getNumCores()
              //Private Class to display only CPU devices in the directory listing
              class CpuFilter implements FileFilter
              @Override
              public boolean accept(File pathname)
              //Check if filename is "cpu", followed by one or more digits
              if(Pattern.matches("cpu[0-9]+", pathname.getName()))
              return true;

              return false;



              try
              //Get directory containing CPU info
              File dir = new File("/sys/devices/system/cpu/");
              //Filter to only list the devices we care about
              File files = dir.listFiles(new CpuFilter());
              //Return the number of cores (virtual CPU devices)
              return files.length;
              catch(Exception e)
              //Default to return 1 core
              return 1;




              This Java code should work in any Android application, even without root.







              share|improve this answer














              share|improve this answer



              share|improve this answer








              edited Mar 22 '18 at 13:22









              Dziugas

              808622




              808622










              answered Apr 30 '12 at 2:44









              DavidDavid

              1,6381526




              1,6381526







              • 1





                the link you've provided is dead . also, i have some questions: it doesn't require any permission, right? also, will it even work when there are more than 9 cores?

                – android developer
                Jul 16 '13 at 7:53












              • Thanks, fixed the link. You shouldn't need any special permissions to run this code (although it could change in later Android versions). If you need to support devices with more than 10 cores, the regexp should look like this: "cpu[0-9]+" (note the extra plus sign). I'll update the post to match.

                – David
                Jul 21 '13 at 12:19











              • thank you for your help.

                – android developer
                Jul 21 '13 at 12:28






              • 1





                4 on Samsung Tab 3, but should return 2

                – Suvitruf
                Dec 15 '13 at 21:19











              • Perhaps it's a hyperthreaded Dual Core processor? This would appear as 4 processors to the system.

                – David
                Jan 2 '14 at 22:59












              • 1





                the link you've provided is dead . also, i have some questions: it doesn't require any permission, right? also, will it even work when there are more than 9 cores?

                – android developer
                Jul 16 '13 at 7:53












              • Thanks, fixed the link. You shouldn't need any special permissions to run this code (although it could change in later Android versions). If you need to support devices with more than 10 cores, the regexp should look like this: "cpu[0-9]+" (note the extra plus sign). I'll update the post to match.

                – David
                Jul 21 '13 at 12:19











              • thank you for your help.

                – android developer
                Jul 21 '13 at 12:28






              • 1





                4 on Samsung Tab 3, but should return 2

                – Suvitruf
                Dec 15 '13 at 21:19











              • Perhaps it's a hyperthreaded Dual Core processor? This would appear as 4 processors to the system.

                – David
                Jan 2 '14 at 22:59







              1




              1





              the link you've provided is dead . also, i have some questions: it doesn't require any permission, right? also, will it even work when there are more than 9 cores?

              – android developer
              Jul 16 '13 at 7:53






              the link you've provided is dead . also, i have some questions: it doesn't require any permission, right? also, will it even work when there are more than 9 cores?

              – android developer
              Jul 16 '13 at 7:53














              Thanks, fixed the link. You shouldn't need any special permissions to run this code (although it could change in later Android versions). If you need to support devices with more than 10 cores, the regexp should look like this: "cpu[0-9]+" (note the extra plus sign). I'll update the post to match.

              – David
              Jul 21 '13 at 12:19





              Thanks, fixed the link. You shouldn't need any special permissions to run this code (although it could change in later Android versions). If you need to support devices with more than 10 cores, the regexp should look like this: "cpu[0-9]+" (note the extra plus sign). I'll update the post to match.

              – David
              Jul 21 '13 at 12:19













              thank you for your help.

              – android developer
              Jul 21 '13 at 12:28





              thank you for your help.

              – android developer
              Jul 21 '13 at 12:28




              1




              1





              4 on Samsung Tab 3, but should return 2

              – Suvitruf
              Dec 15 '13 at 21:19





              4 on Samsung Tab 3, but should return 2

              – Suvitruf
              Dec 15 '13 at 21:19













              Perhaps it's a hyperthreaded Dual Core processor? This would appear as 4 processors to the system.

              – David
              Jan 2 '14 at 22:59





              Perhaps it's a hyperthreaded Dual Core processor? This would appear as 4 processors to the system.

              – David
              Jan 2 '14 at 22:59













              8














              If you're working with a native application, you should try this:



              #include <unistd.h>
              int GetNumberOfProcessor()

              return sysconf(_SC_NPROCESSORS_CONF);



              It work on my i9100 (which availableProcessors() returned 1).






              share|improve this answer



























                8














                If you're working with a native application, you should try this:



                #include <unistd.h>
                int GetNumberOfProcessor()

                return sysconf(_SC_NPROCESSORS_CONF);



                It work on my i9100 (which availableProcessors() returned 1).






                share|improve this answer

























                  8












                  8








                  8







                  If you're working with a native application, you should try this:



                  #include <unistd.h>
                  int GetNumberOfProcessor()

                  return sysconf(_SC_NPROCESSORS_CONF);



                  It work on my i9100 (which availableProcessors() returned 1).






                  share|improve this answer













                  If you're working with a native application, you should try this:



                  #include <unistd.h>
                  int GetNumberOfProcessor()

                  return sysconf(_SC_NPROCESSORS_CONF);



                  It work on my i9100 (which availableProcessors() returned 1).







                  share|improve this answer












                  share|improve this answer



                  share|improve this answer










                  answered Nov 22 '11 at 14:13









                  Thai PhiThai Phi

                  811




                  811





















                      4














                      You can try using Runtime.availableProcessors() as is suggested in this answer



                      Is there any API that tells whether an Android device is dual-core or not?



                      ---edit---



                      A more detailed description is given at Oracle's site




                      availableProcessors



                      public int availableProcessors()


                      Returns the number of processors available to the Java virtual machine.



                      This value may change during a particular invocation of the virtual machine. Applications that are sensitive to the number of available processors should therefore occasionally poll this property and adjust their resource usage appropriately.



                      Returns:



                      the maximum number of processors available to the virtual machine; never smaller than one



                      Since:



                       1.4






                      share|improve this answer

























                      • Awesome Thanks! I hadn't seen that. Just a note: on my Motorola Droid X2 availableProcessors() returns "1" ... when it should return a 2. on a Xoom availableProcessors() correctly returns 2. any other ways?

                        – newbyca
                        Nov 1 '11 at 4:44















                      4














                      You can try using Runtime.availableProcessors() as is suggested in this answer



                      Is there any API that tells whether an Android device is dual-core or not?



                      ---edit---



                      A more detailed description is given at Oracle's site




                      availableProcessors



                      public int availableProcessors()


                      Returns the number of processors available to the Java virtual machine.



                      This value may change during a particular invocation of the virtual machine. Applications that are sensitive to the number of available processors should therefore occasionally poll this property and adjust their resource usage appropriately.



                      Returns:



                      the maximum number of processors available to the virtual machine; never smaller than one



                      Since:



                       1.4






                      share|improve this answer

























                      • Awesome Thanks! I hadn't seen that. Just a note: on my Motorola Droid X2 availableProcessors() returns "1" ... when it should return a 2. on a Xoom availableProcessors() correctly returns 2. any other ways?

                        – newbyca
                        Nov 1 '11 at 4:44













                      4












                      4








                      4







                      You can try using Runtime.availableProcessors() as is suggested in this answer



                      Is there any API that tells whether an Android device is dual-core or not?



                      ---edit---



                      A more detailed description is given at Oracle's site




                      availableProcessors



                      public int availableProcessors()


                      Returns the number of processors available to the Java virtual machine.



                      This value may change during a particular invocation of the virtual machine. Applications that are sensitive to the number of available processors should therefore occasionally poll this property and adjust their resource usage appropriately.



                      Returns:



                      the maximum number of processors available to the virtual machine; never smaller than one



                      Since:



                       1.4






                      share|improve this answer















                      You can try using Runtime.availableProcessors() as is suggested in this answer



                      Is there any API that tells whether an Android device is dual-core or not?



                      ---edit---



                      A more detailed description is given at Oracle's site




                      availableProcessors



                      public int availableProcessors()


                      Returns the number of processors available to the Java virtual machine.



                      This value may change during a particular invocation of the virtual machine. Applications that are sensitive to the number of available processors should therefore occasionally poll this property and adjust their resource usage appropriately.



                      Returns:



                      the maximum number of processors available to the virtual machine; never smaller than one



                      Since:



                       1.4







                      share|improve this answer














                      share|improve this answer



                      share|improve this answer








                      edited May 23 '17 at 10:29









                      Community

                      11




                      11










                      answered Nov 1 '11 at 4:15









                      A.J.A.J.

                      4281520




                      4281520












                      • Awesome Thanks! I hadn't seen that. Just a note: on my Motorola Droid X2 availableProcessors() returns "1" ... when it should return a 2. on a Xoom availableProcessors() correctly returns 2. any other ways?

                        – newbyca
                        Nov 1 '11 at 4:44

















                      • Awesome Thanks! I hadn't seen that. Just a note: on my Motorola Droid X2 availableProcessors() returns "1" ... when it should return a 2. on a Xoom availableProcessors() correctly returns 2. any other ways?

                        – newbyca
                        Nov 1 '11 at 4:44
















                      Awesome Thanks! I hadn't seen that. Just a note: on my Motorola Droid X2 availableProcessors() returns "1" ... when it should return a 2. on a Xoom availableProcessors() correctly returns 2. any other ways?

                      – newbyca
                      Nov 1 '11 at 4:44





                      Awesome Thanks! I hadn't seen that. Just a note: on my Motorola Droid X2 availableProcessors() returns "1" ... when it should return a 2. on a Xoom availableProcessors() correctly returns 2. any other ways?

                      – newbyca
                      Nov 1 '11 at 4:44











                      4














                      This is pretty simple.



                      int numberOfProcessors = Runtime.getRuntime().availableProcessors();


                      Typically it would return 1 or 2. 2 would be in a dual-core CPU.






                      share|improve this answer


















                      • 2





                        Here is an example of using availableProcessprs() to determine the size of pool thread.

                        – bachr
                        Jun 28 '14 at 10:14
















                      4














                      This is pretty simple.



                      int numberOfProcessors = Runtime.getRuntime().availableProcessors();


                      Typically it would return 1 or 2. 2 would be in a dual-core CPU.






                      share|improve this answer


















                      • 2





                        Here is an example of using availableProcessprs() to determine the size of pool thread.

                        – bachr
                        Jun 28 '14 at 10:14














                      4












                      4








                      4







                      This is pretty simple.



                      int numberOfProcessors = Runtime.getRuntime().availableProcessors();


                      Typically it would return 1 or 2. 2 would be in a dual-core CPU.






                      share|improve this answer













                      This is pretty simple.



                      int numberOfProcessors = Runtime.getRuntime().availableProcessors();


                      Typically it would return 1 or 2. 2 would be in a dual-core CPU.







                      share|improve this answer












                      share|improve this answer



                      share|improve this answer










                      answered Aug 4 '13 at 6:32









                      DanKodiDanKodi

                      2,5371919




                      2,5371919







                      • 2





                        Here is an example of using availableProcessprs() to determine the size of pool thread.

                        – bachr
                        Jun 28 '14 at 10:14













                      • 2





                        Here is an example of using availableProcessprs() to determine the size of pool thread.

                        – bachr
                        Jun 28 '14 at 10:14








                      2




                      2





                      Here is an example of using availableProcessprs() to determine the size of pool thread.

                      – bachr
                      Jun 28 '14 at 10:14






                      Here is an example of using availableProcessprs() to determine the size of pool thread.

                      – bachr
                      Jun 28 '14 at 10:14












                      0














                      I use a combination of both available solutions:



                      fun getCPUCoreNum(): Int 
                      val pattern = Pattern.compile("cpu[0-9]+")
                      return Math.max(
                      File("/sys/devices/system/cpu/")
                      .walk()
                      .maxDepth(1)
                      .count pattern.matcher(it.name).matches() ,
                      Runtime.getRuntime().availableProcessors()
                      )






                      share|improve this answer





























                        0














                        I use a combination of both available solutions:



                        fun getCPUCoreNum(): Int 
                        val pattern = Pattern.compile("cpu[0-9]+")
                        return Math.max(
                        File("/sys/devices/system/cpu/")
                        .walk()
                        .maxDepth(1)
                        .count pattern.matcher(it.name).matches() ,
                        Runtime.getRuntime().availableProcessors()
                        )






                        share|improve this answer



























                          0












                          0








                          0







                          I use a combination of both available solutions:



                          fun getCPUCoreNum(): Int 
                          val pattern = Pattern.compile("cpu[0-9]+")
                          return Math.max(
                          File("/sys/devices/system/cpu/")
                          .walk()
                          .maxDepth(1)
                          .count pattern.matcher(it.name).matches() ,
                          Runtime.getRuntime().availableProcessors()
                          )






                          share|improve this answer















                          I use a combination of both available solutions:



                          fun getCPUCoreNum(): Int 
                          val pattern = Pattern.compile("cpu[0-9]+")
                          return Math.max(
                          File("/sys/devices/system/cpu/")
                          .walk()
                          .maxDepth(1)
                          .count pattern.matcher(it.name).matches() ,
                          Runtime.getRuntime().availableProcessors()
                          )







                          share|improve this answer














                          share|improve this answer



                          share|improve this answer








                          edited Nov 15 '18 at 9:12

























                          answered Nov 5 '18 at 21:47









                          G00fYG00fY

                          1168




                          1168



























                              draft saved

                              draft discarded
















































                              Thanks for contributing an answer to Stack Overflow!


                              • Please be sure to answer the question. Provide details and share your research!

                              But avoid


                              • Asking for help, clarification, or responding to other answers.

                              • Making statements based on opinion; back them up with references or personal experience.

                              To learn more, see our tips on writing great answers.




                              draft saved


                              draft discarded














                              StackExchange.ready(
                              function ()
                              StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f7962155%2fhow-can-you-detect-a-dual-core-cpu-on-an-android-device-from-code%23new-answer', 'question_page');

                              );

                              Post as a guest















                              Required, but never shown





















































                              Required, but never shown














                              Required, but never shown












                              Required, but never shown







                              Required, but never shown

































                              Required, but never shown














                              Required, but never shown












                              Required, but never shown







                              Required, but never shown







                              這個網誌中的熱門文章

                              Barbados

                              How to read a connectionString WITH PROVIDER in .NET Core?

                              Node.js Script on GitHub Pages or Amazon S3