如何获取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);