如何获取Android设备名称?我正在使用HTC欲望。当我通过HTC Sync连接它时,软件显示“HTC Smith”的名称。我想通过代码获取这个名称。

这在Android中是如何实现的呢?


当前回答

以下对我有用。

String deviceName = Settings.Global.getString(.getContentResolver(), Settings.Global.DEVICE_NAME);

我不认为这是重复的答案。上面的ppl正在谈论设置安全,为我设置安全是给空,如果我使用设置全局它工作。不管怎样,谢谢你。

其他回答

以下对我有用。

String deviceName = Settings.Global.getString(.getContentResolver(), Settings.Global.DEVICE_NAME);

我不认为这是重复的答案。上面的ppl正在谈论设置安全,为我设置安全是给空,如果我使用设置全局它工作。不管怎样,谢谢你。

首先,

Adb shell getprop >prop_list.txt

第二,

在prop_list.txt中找到您的设备名称以获得道具名称, 例如,我的设备名称是ro.oppo.market.name

最后,

Adb shell getprop ro.oppo.market.name

D:\winusr\adbl

λ adb shell getprop ro.oppo.market.name

成本R17

D:\winusr\adbl

λ

在Android的GNU/Linux环境中,例如,通过非根设备上的Termux UNIX shell,它可以通过/system/bin/getprop命令获得,而每个值的含义都在Android中的Build.java中解释(也在googlesource中):

% /system/bin/getprop | fgrep ro.product | tail -3
[ro.product.manufacturer]: [Google]
[ro.product.model]: [Pixel 2 XL]
[ro.product.name]: [taimen]
% /system/bin/getprop ro.product.model
Pixel 2 XL
% /system/bin/getprop ro.product.model | tr ' ' _
Pixel_2_XL

例如,它可以被设置为tmux中status-right的pane_title,如下所示:

tmux select-pane "$(getprop ro.product.model)"

尝试了这些库,但没有按照我的期望工作,并给出了绝对错误的名称。

所以我自己用同样的数据创建了这个库。 这是链接

AndroidPhoneNamesFinder

要使用这个库,只需添加这个来实现

implementation 'com.github.aishik212:AndroidPhoneNamesFinder:v1.0.2'

然后使用下面的kotlin代码

DeviceNameFinder.getPhoneValues(this, object : DeviceDetailsListener
{  
    override fun details(doQuery: DeviceDetailsModel?) 
    {  
        super.details(doQuery)  
        Log.d(TAG, "details: "+doQuery?.calculatedName)  
    }  
})

这些是您将从DeviceDetailsModel中获得的值

val brand: String? #This is the brandName of the Device  
val commonName: String?, #This is the most common Name of the Device  
val codeName: String?,  #This is the codeName of the Device
val modelName: String?,  #This is the another uncommon Name of the Device
val calculatedName: String?, #This is the special name that this library tries to create from the above data.

Android模拟器示例-

brand=Google 
commonName=Google Android Emulator 
codeName=generic_x86_arm 
modelName=sdk_gphone_x86 
calculatedName=Google Android Emulator

我通过获取蓝牙名称解决了这个问题,但不是从BluetoothAdapter(需要蓝牙权限)获得的。

代码如下:

Settings.Secure.getString(getContentResolver(), "bluetooth_name");

不需要额外的权限。