문제

I am trying to read the phone number in android. I've tried with these codes, but i couldn't get the number.Every one is suggesting this code only,but its not working why?

Suggestions please

Thanks for your precious time!...

MainActvity.java

btn.setOnClickListener(new OnClickListener() {

        @Override
        public void onClick(View v) {
            // TODO Auto-generated method stub

            TelephonyManager mTelephonyMgr = (TelephonyManager)getSystemService(Context.TELEPHONY_SERVICE);
            phonenumber = mTelephonyMgr.getLine1Number();

    System.out.println(">>>----- Phone number-----" + phonenumber);


        }
    });

Manifest.xml

<uses-permission android:name="android.permission.READ_PHONE_STATE"/>
도움이 되었습니까?

해결책

You can check Settings -> About Phone -> Status -> My Phone number in your mobile. This number is returned by getLine1Number(). If it is Unknown, then getLint1Number() will return null or "". Itseems it is Operator/SIM dependent.

다른 팁

Getting phone Number is dependent on sim .For most devices (TelephonyManager.getLine1Number()) will work.For some it may not.You replace with another sim and Check it..

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top