找到设备的唯一名称?
我正在开发一个使用 Zeroconf (bonjour) 来发现设备的应用程序 - 因此我需要为每个 Android 设备提供某种名称(不仅仅是一堆数字和字母,而是一些有意义的名称,例如“Alex 的设备”)。在 iOS 中这可以很容易地完成 - 这在 Android 中可能吗?
I'm developing an app that uses zeroconf (bonjour) to discover devices - so I need to give each android device some kind of name (not just a bunch of numbers and letters, but something meaningful like "Alex's Device"). In iOS it can be easily done - is this possible in android?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
可以有多个帐户链接到该设备。您可以使用 AccountManager 来获取它们。例如,Google 帐户上的电子邮件:
或者,您可以使用 android.os.Build。模型或类似的。
There can be many accounts linked to the device. You can use the AccountManager to get them. For example, emails on google accounts:
Alternatively, you can use android.os.Build.MODEL or similar.
假设您的应用程序需要设备具有网络连接,您可以尝试使用设备的 MAC 地址,该地址应该是全局唯一的。这可以通过 WifiInfo 类获得:
您还需要在清单中设置 ACCESS_WIFI_STATE 权限。
Assuming your application requires a device to have a network connection, you can try using the MAC address of the device, which should be globally unique. This can be obtained with the WifiInfo class:
You'll also need to set the ACCESS_WIFI_STATE permission in your manifest.
你可以获取Android手机的IMEI,它是唯一的,
你可以使用
TelephonyManager
类的方法getDeviceId()
获取它注意: 您需要在清单中添加权限:
READ_PHONE_STATE
you can get the IMEI of the Android Phone , it's Unique ,
you can Get it by using the method
getDeviceId()
of the ClassTelephonyManager
NOTE : you will need to add a permission in your manifest :
READ_PHONE_STATE
有关如何为安装应用程序的每个 Android 设备获取唯一标识符的详细说明,请参阅此官方 Android 开发人员博客文章:
http://android-developers.blogspot.com/2011/03/identifying-app-installations.html
看来最好的方法是你生成安装时请自行阅读,然后在重新启动应用程序时阅读。
我个人认为这是可以接受的,但并不理想。 Android 提供的任何标识符都无法在所有情况下工作,因为大多数标识符都依赖于手机的无线电状态(wifi 开/关、蜂窝网络开/关、蓝牙开/关)。其他如Settings.Secure.ANDROID_ID必须由制造商实现,并且不保证唯一。
以下是将数据写入安装文件的示例,该文件将与应用程序在本地保存的任何其他数据一起存储。
For detailed instructions on how to get a Unique Identifier for each Android device your application is installed from, see this official Android Developers Blog posting:
http://android-developers.blogspot.com/2011/03/identifying-app-installations.html
It seems the best way is for you to generate one your self upon installation and subsequently read it when the application is re-launched.
I personally find this acceptable but not ideal. No one identifier provided by Android works in all instances as most are dependent on the phone's radio states (wifi on/off, cellular on/off, bluetooth on/off). The others like Settings.Secure.ANDROID_ID must be implemented by the manufacturer and are not guaranteed to be unique.
The following is an example of writing data to an INSTALLATION file that would be stored along with any other data the application saves locally.