How to get the phone number of the phone in android code?

后端 未结 2 369
终归单人心
终归单人心 2020-12-15 11:25

I tried googling in google but unable to find the answer

Will anyone please let me know, how can i retrieve the current phone number from the android code. I think p

相关标签:
2条回答
  • 2020-12-15 12:01
    TelephonyManager tm = (TelephonyManager) getSystemService(TELEPHONY_SERVICE);
    String phonenumber = tm.getLine1Number();
    

    This link may be the best collection of TelephonyManager related answers. But still it is not guaranteed that you will be returned a telephone number.

    Check this out!

    0 讨论(0)
  • 2020-12-15 12:03

    You can try:

    TelephonyManager phoneManager = (TelephonyManager) 
        getApplicationContext().getSystemService(Context.TELEPHONY_SERVICE);
    String phoneNumber = phoneManager.getLine1Number();
    

    Needs READ_PHONE_STATE permission.

    0 讨论(0)
提交回复
热议问题