如何获取SIM卡号码的Android? [英] How to fetch sim card number android?
本文介绍了如何获取SIM卡号码的Android?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我想写在Android的简单的应用程序来获取SIM卡号码,我用这个code:
i want to write simple application in android to fetch sim card number,i use this code:
TelephonyManager tMgr = (TelephonyManager)mAppContext.getSystemService(Context.TELEPHONY_SERVICE);
String mPhoneNumber = tMgr.getLine1Number();
写了code的片段插入此块:
write up code in Fragment into this block:
public void onActivityCreated(Bundle savedInstanceState) {
super.onActivityCreated(savedInstanceState);
在这一行:
mAppContext.getSystemService(Context.TELEPHONY_SERVICE);
我得到这个错误部分: mAppContext.getSystemService
。
我该如何解决这个问题?
感谢您关注我的问题。
I get error this part : mAppContext.getSystemService
.
How can i solve that problem?
thanks for you for pay attention to my problem.
推荐答案
获取上下文中的片段
通过使用 getActivity()
get context in Fragment
by using getActivity()
TelephonyManager tMgr = (TelephonyManager)getActivity().getSystemService(Context.TELEPHONY_SERVICE);
这篇关于如何获取SIM卡号码的Android?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文