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

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


当前回答

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

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

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

其他回答

试一试。您可以通过蓝牙获取设备名称。

希望对你有所帮助

public String getPhoneName() {  
        BluetoothAdapter myDevice = BluetoothAdapter.getDefaultAdapter();
        String deviceName = myDevice.getName();     
        return deviceName;
    }

试试这段代码。你会得到android设备名。

public static String getDeviceName() {
    String manufacturer = Build.MANUFACTURER;
    String model = Build.MODEL;
    if (model.startsWith(manufacturer)) {
        return model;
    }
    return manufacturer + " " + model;
}
 static String getDeviceName() {
        try {
            Class systemPropertiesClass = Class.forName("android.os.SystemProperties");
            Method getMethod = systemPropertiesClass.getMethod("get", String.class);
            Object object = new Object();
            Object obj = getMethod.invoke(object, "ro.product.device");
            return (obj == null ? "" : (String) obj);
        } catch (Exception e) {
            e.printStackTrace();
            return "";
        }
    }

你可以通过这种方式得到'idol3'。

首先,

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设备名称,你只需要添加一行代码:

android.os.Build.MODEL;

找到这里:getting-android-device-name