Android getDeviceId
来源:互联网 发布:易语言电视直播源码 编辑:程序博客网 时间:2024/06/06 04:11
Android getDeviceId
获取android设备的IMEI号不是一件难事,方法大家都能百度出来,如下面:
TelephonyManager manager = (TelephonyManager) context.getSystemService(Context.TELEPHONY_SERVICE);
manager.getDeviceId()
上面的写法是对于android sdk level低于23是适用的,但是对于sdk level大于或者等于23的系统来说,这样的写法有时候不适用,获取到的IMEI号可能为空,这时并不表示这个设备没有IMEi号,我们换个方法就可能正确得到IMEi号。其实android sdk不低于23的API提供了一个带参数的getDeviceId方法,参数是卡槽号(0或者1),所以对于android 6.0及以上的系统,正确获取IMEi的写法应该是下面这种形式:
try { final TelephonyManager manager = (TelephonyManager) context.getSystemService(Context.TELEPHONY_SERVICE); if(manager.getDeviceId() == null || manager.getDeviceId().equals("")) { if (Build.VERSION.SDK_INT >= 23) { tac = manager.getDeviceId(0); } }else{ tac = manager.getDeviceId()); }}catch (Exception e){ }
阅读全文
1 0
- android getDeviceId
- Android getDeviceId
- 【Android】java.lang.SecurityException: getDeviceId: Neither user xxxxx nor current process has androi
- 【Android】java.lang.SecurityException: getDeviceId: Neither user xxxxx nor current process has andro
- getDeviceId() 接口说明
- android7.0关于TelephonyManager.getDeviceId()返回null的问题
- [androdi基础知识] 之十六: ((TelephonyManager)paramContext.getSystemService("phone")).getDeviceId();语句的理解
- 双卡双待 getDeviceId unique device ID IMEI 不唯一 会变问题
- Android
- android
- Android
- android
- android
- Android
- Android
- android
- android
- android
- 采用管道函数创建有名管道,使用select函数替代使用poll函数实验多路复用
- Apache POI读合并单元格
- WebView 加载空白问题
- Bluehost服务器虚拟化
- Struts2入门
- Android getDeviceId
- Angularjs-(1)(简介、表达式、指令、控制器、过滤器)
- POMDP详解
- 入门kotlin(下)
- ImageLoader超级详细版
- 浅析ShardPreferences简单数据存储
- 数据库常见面试题
- VirtualBox5.1.24与CentOS-6.5网络设置
- 第3章软件也要拼脸的 3.4.1引入布局