Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to detect android device is 64 bit or 32 bit processor?

I'm trying to find a best solution for this question. The reason is the lib in our application can not run with the 64 bit processor so I need to turn it off in this case. I found that in Android version 21 (lolipop)and higher we can easily detect that the device is 32 bit or 64 bit processor by using Build.SUPPORTED_64_BIT_ABIS and if It returns the String array with 0 elements then... a hah! The device is 32 bit processor. How about lower android version? Build.SUPPORTED_64_BIT_ABIS just only support from android Lolipop version and higher. Thanks & Best Regards, Wish you guys all the best!

like image 222
Tùng Phan Thanh Avatar asked Sep 08 '15 08:09

Tùng Phan Thanh


3 Answers

 try {
            boolean  isArm64 = false;

            BufferedReader localBufferedReader = new BufferedReader(new FileReader("/proc/cpuinfo"));
            if (localBufferedReader.readLine().contains("aarch64")) {
                isArm64 = true;
            }
            localBufferedReader.close();
        } catch (IOException e) {
        }

Or

final boolean is64bit = Build.SUPPORTED_64_BIT_ABIS.length > 0;
like image 96
kakopappa Avatar answered Nov 17 '22 02:11

kakopappa


Simple answer: There's no need to check for this on Android versions below Lollipop. That's due the fact that Lollipop introducted platform support for 64-Bit architectures, Android-Versions below Lollipop won't run with a 64-Bit processor.

Android 5.0 introduces platform support for 64-bit architectures—used by the Nexus 9's NVIDIA Tegra K1. Optimizations provide larger address space and improved performance for certain compute workloads. Apps written in the Java language run as 64-bit apps automatically—no modifications are needed. If your app uses native code, we’ve extended the NDK to support new ABIs for ARM v8, and x86-64, and MIPS-64. (Source)

like image 7
reVerse Avatar answered Nov 17 '22 01:11

reVerse


If you're using ADB

adb shell cat /proc/cpuinfo | grep rch

Most outputs:

Architecture 7 -> 32bit

Architecture 8 -> 64bit

  • this is an extension answer from @Naval Kishor Jha

  • tested in 6 models here

  • no root needed

If you're using JAVA

if(Build.SUPPORTED_64_BIT_ABIS.length>0)
  {
  //it's a 64bit
  }
  else
  {
  //it's a 32bit
  }
like image 7
PYK Avatar answered Nov 17 '22 02:11

PYK