Android:以编程方式获取硬件信息
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/10496872/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Android: Get Hardware Information Programmatically
提问by Heshan Perera
I have a requirement for obtaining the hardware related information on an Android device that runs my application. I need information of the following sort.
我需要在运行我的应用程序的 Android 设备上获取硬件相关信息。我需要以下信息。
- CPU Manufacturer, model and serial number
- SD Card Manufacturer and serial number
- Camera Manufacturer and other related specs
- Bluetooth related hardware information
- WiFi related hardware information
- RAM Vendor / model
- Display vendor and model
- CPU 制造商、型号和序列号
- SD 卡制造商和序列号
- 相机制造商和其他相关规格
- 蓝牙相关硬件信息
- WiFi相关硬件信息
- 内存供应商/型号
- 显示供应商和型号
Any help on this topic would be highly appreciated.
对此主题的任何帮助将不胜感激。
回答by Richa
Log.i("ManuFacturer :", Build.MANUFACTURER);
Log.i("Board : ", Build.BOARD);
Log.i("Display : ", Build.DISPLAY);
More info can be found at from http://developer.android.com/reference/android/os/Build.html
更多信息可以从http://developer.android.com/reference/android/os/Build.html找到
回答by Yamini
Log.i("TAG", "SERIAL: " + Build.SERIAL);
Log.i("TAG","MODEL: " + Build.MODEL);
Log.i("TAG","ID: " + Build.ID);
Log.i("TAG","Manufacture: " + Build.MANUFACTURER);
Log.i("TAG","brand: " + Build.BRAND);
Log.i("TAG","type: " + Build.TYPE);
Log.i("TAG","user: " + Build.USER);
Log.i("TAG","BASE: " + Build.VERSION_CODES.BASE);
Log.i("TAG","INCREMENTAL " + Build.VERSION.INCREMENTAL);
Log.i("TAG","SDK " + Build.VERSION.SDK);
Log.i("TAG","BOARD: " + Build.BOARD);
Log.i("TAG","BRAND " + Build.BRAND);
Log.i("TAG","HOST " + Build.HOST);
Log.i("TAG","FINGERPRINT: "+Build.FINGERPRINT);
Log.i("TAG","Version Code: " + Build.VERSION.RELEASE);
回答by M Talha
**This Code give you information about following **
**此代码为您提供有关以下内容的信息**
- Manufacturer of device
- Brand
- Model
- Board
- Hardware
- Serial No.
- Android_ID
- Screen Resolution
- Screen Density
- Boot Loader
- User
- Host
- API Level
- Build ID
- Build Time
Fingerprint
DisplayMetrics dm = new DisplayMetrics(); getActivity().getWindowManager().getDefaultDisplay().getMetrics(dm); double x = Math.pow(mWidthPixels / dm.xdpi, 2); double y = Math.pow(mHeightPixels / dm.ydpi, 2); screenInches = Math.sqrt(x + y); rounded = df2.format(screenInches); densityDpi = (int) (dm.density * 160f); Manufacturer_value = Build.MANUFACTURER; Brand_value = Build.BRAND; Model_value = Build.MODEL; Board_value = Build.BOARD; Hardware_value = Build.HARDWARE; Serial_nO_value = Build.SERIAL; UID_value = tManager.getDeviceId(); android_id = Settings.Secure.getString(getContext().getContentResolver(), Settings.Secure.ANDROID_ID); ScreenResolution_value = mHeightPixels + " * " + mWidthPixels + " Pixels"; screen_size = rounded + " Inches"; screen_density = String.valueOf(densityDpi) + " dpi"; BootLoader_value = Build.BOOTLOADER; User_value = Build.USER; Host_value = Build.HOST; Version = Build.VERSION.RELEASE; API_level = Build.VERSION.SDK_INT + ""; Build_ID = Build.ID; Build_Time = Build.TIME + ""; Fingerprint = Build.FINGERPRINT;
- 设备制造商
- 牌
- 模型
- 木板
- 硬件
- 序列号。
- 安卓_ID
- 屏幕分辨率
- 屏幕密度
- 引导加载程序
- 用户
- 主持人
- API 级别
- 构建 ID
- 构建时间
指纹
DisplayMetrics dm = new DisplayMetrics(); getActivity().getWindowManager().getDefaultDisplay().getMetrics(dm); double x = Math.pow(mWidthPixels / dm.xdpi, 2); double y = Math.pow(mHeightPixels / dm.ydpi, 2); screenInches = Math.sqrt(x + y); rounded = df2.format(screenInches); densityDpi = (int) (dm.density * 160f); Manufacturer_value = Build.MANUFACTURER; Brand_value = Build.BRAND; Model_value = Build.MODEL; Board_value = Build.BOARD; Hardware_value = Build.HARDWARE; Serial_nO_value = Build.SERIAL; UID_value = tManager.getDeviceId(); android_id = Settings.Secure.getString(getContext().getContentResolver(), Settings.Secure.ANDROID_ID); ScreenResolution_value = mHeightPixels + " * " + mWidthPixels + " Pixels"; screen_size = rounded + " Inches"; screen_density = String.valueOf(densityDpi) + " dpi"; BootLoader_value = Build.BOOTLOADER; User_value = Build.USER; Host_value = Build.HOST; Version = Build.VERSION.RELEASE; API_level = Build.VERSION.SDK_INT + ""; Build_ID = Build.ID; Build_Time = Build.TIME + ""; Fingerprint = Build.FINGERPRINT;
回答by cadavre
You can also get real-time hardware info. Build.* parameters are set during compilation of Android before even deploying it on hardware itself.
您还可以获得实时硬件信息。Build.* 参数在 Android 编译期间设置,甚至在将其部署到硬件本身之前。
You can access Linux real-time hardware info by reading /proc/* "files".
您可以通过读取 /proc/* "files" 来访问 Linux 实时硬件信息。
You can do that with https://stackoverflow.com/a/3528239/997381
你可以用https://stackoverflow.com/a/3528239/997381做到这一点
Simply as command put cat /proc/cpuinfo
.
就像命令一样cat /proc/cpuinfo
。
You can test this with adb shell
, and you don't need root permissions.
您可以使用 进行测试adb shell
,并且不需要 root 权限。
回答by ry8806
The "Build" class in android.os looks like it will contain some of the information you require
android.os 中的“Build”类看起来将包含您需要的一些信息
use it as
用它作为
string build = Build.VERSION.DEVICE;
回答by Cube Studio
maybe someone needs kotlin solution
也许有人需要 kotlin 解决方案
class DeviceInfoHelper constructor(val context: Context) {
val model = deviceModel
val imei = context.imei
val hardware: String? = HARDWARE
val board: String? = BOARD
val bootloader: String? = BOOTLOADER
val user: String? = USER
val host: String? = HOST
val version: String? = RELEASE
val apiLevel = SDK_INT
val id: String? = ID
val time = TIME
val fingerPrint: String? = FINGERPRINT
val display: String? = DISPLAY
private val deviceModel
@SuppressLint("DefaultLocale")
get() = capitalize(
if (MODEL.toLowerCase().startsWith(MANUFACTURER.toLowerCase())) {
MODEL
} else {
"$MANUFACTURER $MODEL"
})
private fun capitalize(str: String) = str.apply {
if (isNotEmpty()) {
first().run { if (isLowerCase()) toUpperCase() }
}
}
private val Context.imei
@SuppressLint("HardwareIds", "MissingPermission")
get() = telephonyManager?.run {
if (isReadPhoneStatePermissionGranted()) {
if (SDK_INT >= VERSION_CODES.O) {
imei
} else {
deviceId
}
} else DEFAULT_DEVICE_ID
} ?: DEFAULT_DEVICE_ID
private fun Context.isReadPhoneStatePermissionGranted() =
ContextCompat.checkSelfPermission(
this,
Manifest.permission.READ_PHONE_STATE
) == PackageManager.PERMISSION_GRANTED
private val Context.telephonyManager
get() = getSystemService(Context.TELEPHONY_SERVICE) as TelephonyManager?
}
}