Programmatically obtain the phone number of the Android phone

后端 未结 18 1986
南笙
南笙 2020-11-21 06:17

How can I programmatically get the phone number of the device that is running my android app?

18条回答
  •  不要未来只要你来
    2020-11-21 06:45

    A little contribution. In my case, the code launched an error exception. I have needed put an annotation that for the code be run and fix that problem. Here I let this code.

    public static String getLineNumberPhone(Context scenario) {
        TelephonyManager tMgr = (TelephonyManager) scenario.getSystemService(Context.TELEPHONY_SERVICE);
        @SuppressLint("MissingPermission") String mPhoneNumber = tMgr.getLine1Number();
        return mPhoneNumber;
    }
    

提交回复
热议问题