Best way to get user-defined custom name for an Android device

时光毁灭记忆、已成空白 提交于 2021-02-19 06:20:13

问题


What is the best way to get user-defined custom name of an Android device?

Some phones treat both device name and bluetooth name as the same. In these cases I could get the bluetooth name. In some phones there is a setting called Owner Info, under Security->Settings. How can I read the name from that? Or is there anything else you would suggest for my scenario? Understand that I'm not asking for the profile name from People app or the model / manufacturer of the phone.


回答1:


I have posted this answer before:

Use

String ownerInfo = Settings.Secure.getString(getContentResolver(),
        "lock_screen_owner_info");

Make sure to catch SettingNotFoundException

Update

As of Android 4.4.2 the owner info value is moved to lock screen database,/data/system/locksettings.db, to which 3rd-party apps have no read/write access. That's, there is no reliable way of reading owner info for later Android versions.




回答2:


//this could work, but sometimes null

Settings.Secure.getString(getContentResolver(), "device_name")

//Bluetooth name, no extra permissions

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

//p2p enabled devices could have it in here

Settings.Secure.getString(getContentResolver(), "wifi_p2p_device_name")

you always can check using this command:

adb shell settings list global



回答3:


I am running 4.4.2 and the following works:

Settings.System.getString(getContentResolver(), "device_name")



来源:https://stackoverflow.com/questions/23697766/best-way-to-get-user-defined-custom-name-for-an-android-device

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!