【安卓】通过反射获取手机的imsi号 |
您所在的位置:网站首页 › 中央五台中日女排大奖赛直播时间 › 【安卓】通过反射获取手机的imsi号 |
Class telephonyManager = null;
String imsi = null;
try{
telephonyManager = Class.forName("android.telephony.TelephonyManager");
Method method=telephonyManager.getMethod("getSubscriberId");
imsi = (String) method.invoke(telephonyManager.getMethod("getDefault").invoke(null));
catch(Exception e){
e.printStackTrace();
}
获取手机的imsi可以使用TelephonyManager这个类里面的getSubscriberId()方法,获取imei就可以用getDeviceId()这个方法。 我使用的是反射,先获取TelephonyManager这个类的Class对象,然后调用getSubscriberId()方法。一开始调用方法的时候遇到了问题,因为方法invoke的时候需要一个对象作为参数,而TelephonyManager这个类的实例化不能用构造函数(api文档上有带Context参数的构造函数,但是我调用编译器提示说不存在),于是我又翻阅api文档,发现getDefault()这个静态函数返回一个TelepManager的实例,于是问题解决~
|
今日新闻 |
点击排行 |
|
推荐新闻 |
图片新闻 |
|
专题文章 |
CopyRight 2018-2019 实验室设备网 版权所有 win10的实时保护怎么永久关闭 |