没有合适的资源?快使用搜索试试~ 我知道了~
Android获取手机本机号码的实现方法
1.该资源内容由用户上传,如若侵权请联系客服进行举报
2.虚拟产品一经售出概不退款(资源遇到问题,请及时私信上传者)
2.虚拟产品一经售出概不退款(资源遇到问题,请及时私信上传者)
版权申诉
3星 · 超过75%的资源 32 下载量 54 浏览量
2020-08-29
05:09:24
上传
评论 2
收藏 32KB PDF 举报
温馨提示
试读
2页
主要介绍了Android获取手机本机号码的实现方法的相关资料,希望通过本文大家能够实现这样的方法,需要的朋友可以参考下
资源推荐
资源详情
资源评论
Android获取手机本机号码的实现方法获取手机本机号码的实现方法
主要介绍了Android获取手机本机号码的实现方法的相关资料,希望通过本文大家能够实现这样的方法,需要的朋
友可以参考下
Android获取手机本机号码的实现方法获取手机本机号码的实现方法
反射TelephoneManager 获取本机号码,注意一下提供的接口有的SIM卡没写是获取不到的,该接口只适配Android5.0以上版
本
public String getMsisdn(int slotId) {
return getLine1NumberForSubscriber(getSubIdForSlotId(slotId));
}
权限
<uses-permission android:name="android.permission.READ_PHONE_STATE"/>
public class RegisterMessage {
private static Context mContext;
private static TelephonyManager mTelephonyManager;
private ConnectivityManager mConnMngr;
private static SubscriptionManager mSubscriptionManager;
public RegisterMessage(Context context) {
mContext = context;
mTelephonyManager = (TelephonyManager) context.getSystemService(Context.TELEPHONY_SERVICE);
if (mTelephonyManager == null) {
throw new Error("telephony manager is null");
}
mConnMngr = (ConnectivityManager) context
.getSystemService(Context.CONNECTIVITY_SERVICE);
mSubscriptionManager = SubscriptionManager.from(mContext);
}
public String getMsisdn(int slotId) {//slotId 0为卡1 ,1为卡2
return getLine1NumberForSubscriber(getSubIdForSlotId(slotId));
}
rivate int getSubIdForSlotId(int slotId) {
int[] subIds = getSubId(slotId);
if (subIds == null || subIds.length < 1 || subIds[0] < 0) {
return -1;
}
MLog.d("getSubIdForSlotId = "+subIds[0]);
return subIds[0];
}
private static int[] getSubId(int slotId) {
Method declaredMethod;
int[] subArr = null;
try {
declaredMethod = Class.forName("android.telephony.SubscriptionManager").getDeclaredMethod("getSubId", new Class[]{Integer.TYPE});
declaredMethod.setAccessible(true);
subArr = (int[]) declaredMethod.invoke(mSubscriptionManager,slotId);
} catch (ClassNotFoundException e) {
e.printStackTrace();
declaredMethod = null;
} catch (IllegalArgumentException e2) {
e2.printStackTrace();
declaredMethod = null;
} catch (NoSuchMethodException e3) {
e3.printStackTrace();
declaredMethod = null;
} catch (ClassCastException e4) {
e4.printStackTrace();
declaredMethod = null;
} catch (IllegalAccessException e5){
e5.printStackTrace();
declaredMethod = null;
}catch (InvocationTargetException e6){
e6.printStackTrace();
declaredMethod = null;
}
if(declaredMethod == null) {
subArr = null;
资源评论
- 悟柯2021-03-05我也不知道哪里出了问题,没有获得手机号码
- qq_344248962023-11-26这个资源值得下载,资源内容详细全面,与描述一致,受益匪浅。
weixin_38506713
- 粉丝: 4
- 资源: 907
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
最新资源
- Screenshot_20240427_031602.jpg
- 网页PDF_2024年04月26日 23-46-14_QQ浏览器网页保存_QQ浏览器转格式(6).docx
- 直接插入排序,冒泡排序,直接选择排序.zip
- 在排序2的基础上,再次对快排进行优化,其次增加快排非递归,归并排序,归并排序非递归版.zip
- 实现了7种排序算法.三种复杂度排序.三种nlogn复杂度排序(堆排序,归并排序,快速排序)一种线性复杂度的排序.zip
- 冒泡排序 直接选择排序 直接插入排序 随机快速排序 归并排序 堆排序.zip
- 课设-内部排序算法比较 包括冒泡排序、直接插入排序、简单选择排序、快速排序、希尔排序、归并排序和堆排序.zip
- Python排序算法.zip
- C语言实现直接插入排序、希尔排序、选择排序、冒泡排序、堆排序、快速排序、归并排序、计数排序,并带图详解.zip
- 常用工具集参考用于图像等数据处理
资源上传下载、课程学习等过程中有任何疑问或建议,欢迎提出宝贵意见哦~我们会及时处理!
点击此处反馈
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功