如何检查android设备的体系结构并显示它们? [英] How to check Architecture of android device and show them?

查看:79
本文介绍了如何检查android设备的体系结构并显示它们?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在开发一个适用于设备体系结构的应用程序,这意味着如果用户使用32位手机,它将显示一些不同的功能,而对于64位手机,它将显示一些其他功能.如果有一种方法,也可以在设备上打印其位并告知用户.预先感谢

解决方案

我的答案来自Patel和Majumder.如果要使用特定的体系结构进行操作,则应检查要使用的特定指令集(如果要查找的内容多于32位或64位,则更多).您可以在此处查看说明.

正如Patel解释的那样,在API级别21之后,一些值已被弃用,因此您应在调用函数之前检查这些值.我提供了一些代码,可以帮助您进行检查.

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
    }

}

您还可以通过选择 Debug (调试)并在搜索字段中输入 Supported ABIS (支持的ABIS),在 Android Monitor 上查看所有这些信息.希望这会有所帮助.

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

解决方案

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.

这篇关于如何检查android设备的体系结构并显示它们?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆