如何获取SIM卡号码的Andr​​oid?卡号、SIM、oid、Andr

2023-09-03 21:58:15 作者:我们之间的关系像一场游戏,我练到满级,你删了游戏。今天小编为

我想写在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);