gpt4 book ai didi

java - 如何检查 Android 设备的架构并显示它们?

转载 作者:搜寻专家 更新时间:2023-11-01 08:30:11 25 4
gpt4 key购买 nike

我正在开发一款适用于设备架构的应用程序,这意味着如果用户使用的是 32 位手机,它将显示一些不同的功能,而对于 64 位手机则显示一些其他功能。如果有一种方法也可以在设备上打印他们的位并让用户知道。提前致谢

最佳答案

我的回答借鉴了 Patel 和 Majumder。如果你想用特定的架构做一些事情,那么你应该检查你想在哪个特定的指令集下工作(如果你想了解更多,而不是仅仅 32 位或 64 位)。您可以查看 ABI 的描述 here .

正如 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
}

}

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

关于java - 如何检查 Android 设备的架构并显示它们?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41605726/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com