Search code examples
androidtelephonymanager

how to get international dialing code based on SIM provider?


i am developing the application in which user mobile no and international country code should be set automatically on the basis of SIM card provider.

i.e if i install this application in first page country code and my phone no should be filled automatically.i want this result as my output.enter image description here

i have done this using static code but i want to do dynamically.if user uses this application then country code and mobile no should be selected automatically.

i have searched on net but there is not a exact answer of this question.

I have seen the application in which they are doing this thing so how they are doing?

Thanks


Solution

  • Here is the code snippet that will help you in getting the phone number:

    TelephonyManager tMgr = (TelephonyManager)mAppContext.getSystemService(Context.TELEPHONY_SERVICE);
    String phoneNumber = tMgr.getLine1Number();
    

    Don't forget to include READ_PHONE_STATE permission in manifest file.