如何在android中以编程方式获取设备的IMEI/ESN? [英] How to get the device's IMEI/ESN programmatically in android?

查看:41
本文介绍了如何在android中以编程方式获取设备的IMEI/ESN?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

为了唯一地标识每个设备,我想使用 IMEI(或 CDMA 设备的 ESN 号码).如何以编程方式访问它?

To identify each devices uniquely I would like to use the IMEI (or ESN number for CDMA devices). How to access this programmatically?

推荐答案

您想调用 android.telephony.TelephonyManager.getDeviceId().

这将返回唯一标识设备的任何字符串(GSM 上的 IMEI,CDMA 上的 MEID).

This will return whatever string uniquely identifies the device (IMEI on GSM, MEID for CDMA).

您需要在 AndroidManifest.xml 中获得以下权限:

You'll need the following permission in your AndroidManifest.xml:

<uses-permission android:name="android.permission.READ_PHONE_STATE"/>

为了做到这一点.

话虽如此,做这件事要小心.用户不仅会想知道为什么您的应用程序要访问他们的电话堆栈,而且如果用户获得新设备,可能难以迁移数据.

That being said, be careful about doing this. Not only will users wonder why your application is accessing their telephony stack, it might be difficult to migrate data over if the user gets a new device.

更新:正如下面的评论中提到的,这不是一种对用户进行身份验证的安全方式,并且会引起隐私问题.不推荐.相反,如果您想实现无摩擦,请查看 Google+ 登录 API登录系统.

Update: As mentioned in the comments below, this is not a secure way to authenticate users, and raises privacy concerns. It is not recommended. Instead, look at the Google+ Login API if you want to implement a frictionless login system.

Android 备份 API 如果您只想要一个当用户重置手机(或购买新设备)时,持久化一组字符串的轻量级方法.

The Android Backup API is also available if you just want a lightweight way to persist a bundle of strings for when a user resets their phone (or buys a new device).

这篇关于如何在android中以编程方式获取设备的IMEI/ESN?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆