I am working on a app which works on the Architecture of devices, means if user is using 32bit phone, it will show some different function andfor 64bit some other function. If there is a way that can also print their bit on device and let user know. Thank in advance
-
are u trying to ask the hardware information? – W4R10CK Jan 12 '17 at 06:00
-
Possible duplicate of [Android: Get mobile hardware information](http://stackoverflow.com/questions/39530765/android-get-mobile-hardware-information) – W4R10CK Jan 12 '17 at 06:01
3 Answers
My answer borrows from both Patel and Majumder. If you want to do something with a specific architecture, then you should check for which specific instruction set you want to work under(if you want to find out more than if it just 32 or 64 bit). You can see descriptions for the ABIs here.
As explained by Patel, after API Level 21, some of the values become deprecated so you should check for those before calling on your functions. I have provided some code yo help you check for this.
final String DEBUG_TAG_ARC = "Supported ABIS";
int OSNumber = Integer.valueOf(Build.VERSION.SDK_INT);
Toast.makeText(this, "API: "+OSNumber, Toast.LENGTH_SHORT).show();
Log.d(DEBUG_TAG_ARC, "API: "+OSNumber);
//if OS is less than API 21
if(OSNumber < Build.VERSION_CODES.LOLLIPOP ) {
String archType = Build.CPU_ABI2;
Toast.makeText(this, archType, Toast.LENGTH_SHORT).show();
String archType2 = Build.CPU_ABI2;
Toast.makeText(this, archType2, Toast.LENGTH_SHORT).show();
Log.d(DEBUG_TAG_ARC, "Supports the following: "+archType+" and "+archType2);
//here is were you do something with the values
//somthing like this
//32BIT
if(archType.equals("x86") || archType.equals("x86")){
//do something
}
//64BIT
else if(archType.equals("x86_64") || archType.equals("x86_64")){
//do something
}
}
//if OS is greater than or equal toAPI 21
//check for supported ABIS
if(OSNumber >= Build.VERSION_CODES.LOLLIPOP ) {
String[] supportedABIS = Build.SUPPORTED_ABIS;
String[] supportedABIS_32_BIT = Build.SUPPORTED_32_BIT_ABIS;
String[] supportedABIS_64_BIT = Build.SUPPORTED_64_BIT_ABIS;
for(String aSupportedABI: supportedABIS){
Log.d(DEBUG_TAG_ARC, aSupportedABI);
}
for(String aSupportedABI: supportedABIS_32_BIT){
Log.d(DEBUG_TAG_ARC, "32BIT : "+aSupportedABI);
}
for(String aSupportedABI: supportedABIS_64_BIT){
Log.d(DEBUG_TAG_ARC, "64BIT : "+aSupportedABI);
}
//checks that there is support for 32 or 64BIT
Log.d(DEBUG_TAG_ARC,"length of 32BIT support: "+supportedABIS_32_BIT.length);
Log.d(DEBUG_TAG_ARC,"length of 64BIT support: "+supportedABIS_64_BIT.length);
//to do something with the 32BIT Architecture
//if there is nothing (0) in the ordered list then it means that it does not support it
if(supportedABIS_32_BIT.length > 0 ){
//do something with the 32BIT ARCH
}
//to do something with the 64BIT Architecture
//if there is nothing (0) in the ordered list then it means that it does not support it
else if(supportedABIS_64_BIT.length > 0 ){
//do something with the 64BIT ARCH
}
}
You can also see all of this information on the Android Monitor by selecting Debug and entering Supported ABIS into the search field. Hope this helps.

- 187
- 3
- 12
-
Thanks for your Answer, but may I know how can I display this as app, which will tell user that which bit he/she using? – Kanishq Gupta Jan 12 '17 at 08:57
-
you can use `Toast.makeText(this, "show ABI", Toast.LENGTH_SHORT).show();` to achieve this by where it it says in the code `//do something` and in the end on the `if` and `if else` statements. – Salvador Hernandez Jan 12 '17 at 09:01
-
What is the point of your code lke this `archType.equals("x86_64") || archType.equals("x86_64")` The OR operation is not needed since you are checking for the same thing. – kuchi May 28 '20 at 05:33
Checkout Build (android.os.build)
Get the information about CPU and ABIs
String cpuABI = Build.CPU_ABI; // Return the name of the instruction set (CPU type + ABI convention) of native code.
String cpuABI2 = Build.CPU_ABI2; // Return The name of the second instruction set (CPU type + ABI convention) of native code.
Above two fields were deprecated in API level 21.
Use below fields for API level 21 or higher.
String[] supportedABIS = Build.SUPPORTED_ABIS; // Return an ordered list of ABIs supported by this device.
String[] supported32BitABIS = Build.SUPPORTED_32_BIT_ABIS; // Return an ordered list of 32 bit ABIs supported by this device.
String[] supported64BitABIS = Build.SUPPORTED_64_BIT_ABIS; // Return an ordered list of 64 bit ABIs supported by this device.

- 12,244
- 8
- 65
- 85
-
1Thanks for answer, may I know that how it will show the device is 32 bit or 64bit? – Kanishq Gupta Jan 12 '17 at 06:55
https://developer.android.com/reference/android/os/Build.html
Go to the above reference, the Strings at fields section can be used.
If you want to show device Architecture in a toast, then use this below code;
String abi = Build.CPU_ABI;
Toast arc = Toast.makeText(getApplicationContext(), "Device Architecture is "+ abi, Toast.LENGTH_LONG);
arc.show();
-
Thanks for answer, may I know that how it will show the device is 32 bit or 64bit? – Kanishq Gupta Jan 12 '17 at 06:55
-
If device is 32 , trying to return 64 bit will may return null, check this way. and I'm also 17years old kanu. – Jun 19 '17 at 07:04
-
-
You should remember that if target device is API level 21 or newer only then you will be able to check this. – Jun 19 '17 at 07:06