DeviceId() 显示空指针?
我正在开发一个应用程序,因为我只需要设备的 IMIE 号码...
我尝试过:
telephonyManager = (TelephonyManager)getSystemService(Context.TELEPHONY_SERVICE);
imie = telephonyManager.getDeviceId();
在 Menifyst 中:
<uses-permission android:name="android.permission.READ_PHONE_STATE"/>
让我告诉我,是否需要执行任何其他操作?
提前致谢。
i am developing an app in that i just need IMIE number of device...
I tried:
telephonyManager = (TelephonyManager)getSystemService(Context.TELEPHONY_SERVICE);
imie = telephonyManager.getDeviceId();
In Menifiest:
<uses-permission android:name="android.permission.READ_PHONE_STATE"/>
Let me tell, if that require any other things to do??
thanks in advance.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
我认为你做得对,但根据 Android开发者博客:
此外,它可能无法在模拟器上运行。
I think you're doing it right, but according to the Android Developers Blog:
Also, it probably won't work on an emulator.
这不是设备的 IMIE 号码,但如果您只需要设备的标识符,您也可以尝试
Build.SERIAL
。与 getDeviceId() 类似,该值可能并不总是唯一或可用,但它是第一个方法失败时尝试的另一个选项。This is not the IMIE number for the device but if you just need an identifier for the device, you can also try
Build.SERIAL
. LikegetDeviceId()
the value might not always be unique or available but it's another option to try when the first method fails.以下可能无法在模拟器上正常工作。
现在有时需要从非电话设备(例如平板电脑)获取唯一编号,此时我们可以创建伪唯一 ID,该 ID 适用于所有 Android 设备,它提供像 IMIE 这样的唯一编号。以这种方式计算的 ID 不会是唯一的:可以找到具有相同 ID 的两个设备(基于相同的硬件和 ROM 映像),但在实际应用中的机会可以忽略不计。为此,您可以使用 Build 类:
PUID 将返回 13 位数字,我们在前面添加两个数字 (35),以具有与 IMEI(15 位数字)相同大小的 ID。
很棒的想法是我们不需要使用上面的代码添加 READ_PHONE_STATE 权限。
如需生成唯一编号的更多帮助,请访问 pocket magic。
following may not work properly on emulator..
Now sometimes its require to get the unique number from non-telephonic device (e.g Tablet) at that time we can create Pseudo-Unique ID, that works on all Android devices which gives unique number like IMIE. The ID computed in this way won't be unique: it is possible to find two devices with the same ID (based on the same hardware and rom image) but the chances in real world applications are negligible. For this purpose you can use the Build class:
PUID will return 13 digits number and we are adding two more in front (35) to have the same size ID like the IMEI (15 digits).
and great think is that we do not need to add READ_PHONE_STATE permission using above code.
For more help in generating unique number visit pocket magic.