以编程方式获取Android手机型号,如何在android中以编程方式获取设备名称和型号?
我想知道是否有一种方法可以在 Android 中以编程方式读取手机型号。
我想要一条像 HTC Dream、Milestone、Sapphire 之类的字符串...
I would like to know if there is a way for reading the Phone Model programmatically in Android.
I would like to get a string like HTC Dream, Milestone, Sapphire or whatever...
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(16)
我使用以下代码来获取完整的设备名称。它获取型号和制造商字符串并将它们连接起来,除非型号字符串已经包含制造商名称(在某些手机上确实如此)
:
以下是我从用户那里获得的设备名称的一些示例:
I use the following code to get the full device name. It gets model and manufacturer strings and concatenates them unless model string already contains manufacturer name (on some phones it does):
Here are a few examples of device names I got from the users:
在许多流行的设备上,该设备的市场名称不可用。例如,在 Samsung Galaxy S6 上,
Build.MODEL
的值可能是"SM-G920F"
、"SM-G920I"
或“SM-G920W8”
。我创建了一个小型库,用于获取设备的市场(消费者友好)名称。它为超过 10,000 设备获取正确的名称,并且不断更新。如果您想使用我的库,请单击以下链接:
Github 上的 AndroidDeviceNames 库
如果您不想使用上面的库,那么这是获得消费者友好的设备名称的最佳解决方案:
以我的 Verizon HTC One M8 为例:
结果:
On many popular devices the market name of the device is not available. For example, on the Samsung Galaxy S6 the value of
Build.MODEL
could be"SM-G920F"
,"SM-G920I"
, or"SM-G920W8"
.I created a small library that gets the market (consumer friendly) name of a device. It gets the correct name for over 10,000 devices and is constantly updated. If you wish to use my library click the link below:
AndroidDeviceNames Library on Github
If you do not want to use the library above, then this is the best solution for getting a consumer friendly device name:
Example from my Verizon HTC One M8:
Result:
是的:Build.MODEL。
Yes: Build.MODEL.
对于那些寻找
Build
属性的完整列表的人,这里是 Sony Z1 Compact 的示例:您可以使用 kotlin 使用“评估表达式”对话框在调试模式下轻松列出设备的这些属性:
For whom who looking for full list of properties of
Build
here is an example for Sony Z1 Compact:You can easily list those properties for your device in debug mode using "evaluate expression" dialog using kotlin:
事实上这并不是100%正确。这可以给你模型(有时是数字)。
将为您提供手机制造商(您请求的 HTC 部分):
对于产品名称:
Actually that is not 100% correct. That can give you Model (sometime numbers).
Will get you the Manufacturer of the phone (HTC portion of your request):
For a product name:
Kotlin 简短版本:
Kotlin short version:
显然,您需要使用 Google 的列表:https://support.google.com/googleplay/answer/1727131
API 不会返回我期望的任何内容,也不会返回“设置”中的任何内容。对于我的 Motorola X,这就是我
转到上面提到的页面时得到的“幽灵”映射到 Moto X。似乎这样可能会更简单一点...
Apparently you need to use the list from Google at https://support.google.com/googleplay/answer/1727131
The APIs don't return anything I expect or anything in Settings. For my Motorola X this is what I get
Going to the page mentioned above "ghost" maps to Moto X. Seems like this could be a tad simpler...
当您想要检索制造商、设备名称和/或型号时,可以使用以下字符串:
The following strings are all of use when you want to retrieve manufacturer, name of the device, and/or the model:
Build.DEVICE 为某些设备提供人类可读的名称 <代码>构建.MODEL
Build.DEVICE Gives the human readable name for some devices than
Build.MODEL
您可以使用以下代码来获取品牌名称和
设备的品牌型号。
you can use the following code for getting the brand name and
brand model of the device.
这是我的代码,要获取制造商、品牌名称、操作系统版本和支持 API 级别
输出:
Here is my code , To get Manufacturer,Brand name,Os version and support API Level
Output:
Kotlin版本
Kotlin version
稍微改变了 Idolons 代码。这将在获取设备型号时将单词大写。
Changed Idolons code a little. This will capitalize words when getting the device model.
您可以从以下位置获取电话设备名称
如果手机不支持蓝牙,那么您必须从以下位置构造设备名称
这是获取手机设备名称的示例代码。
You can get the phone device name from the
In case phone doesn't support Bluetooth, then you have to construct the device name from
Here is the sample code to get the phone device name.
您可以尝试以下函数,它以字符串格式返回您的手机型号名称。
You can Try following function and its return your phoneModel name in string format.