Android: detect your own phone number

In this tutorial you will learn how to detect your own phone number programmatically



Step: add permission to Android Manifest

    <uses-permission android:name="android.permission.READ_PHONE_STATE"/>
</manifest>



Step: use TelephonyManager to read the number

   private String getMyPhoneNumber() {
      TelephonyManager manager = (TelephonyManager) appContext.getSystemService(Context.TELEPHONY_SERVICE);
      String myPhoneNumber = manager.getLine1Number();
      return myPhoneNumber;
   }






As an Amazon Associate I earn from qualifying purchases.

No comments:

Post a Comment

Post Scriptum

The views in this article are mine and do not reflect those of my employer.
I am preparing to cancel the subscription to the e-mail newsletter that sends my articles.
Follow me on:
X.com (Twitter)
LinkedIn
Google Scholar

Popular Recent Posts

Most Popular Articles

apt quotation..