Reading device phone number throws NULLPointerException

后端 未结 5 1876
时光取名叫无心
时光取名叫无心 2020-12-21 23:48

I am trying to read the phone number of the device using the following code. When phone number is not available I read the subcriber id. It works in some phones and throws N

5条回答
  •  感动是毒
    2020-12-22 00:48

    TelephonyManager tm = (TelephonyManager) getSystemService(TELEPHONY_SERVICE);

    String number = tm.getLine1Number();

提交回复
热议问题