سؤال

I would like to know is there a way to retrieve a mobile phone number from inside a custom Android application?


There is a class TelephonyManager but I could not see a method that reads GSM number from phone or SIM card. I have to add that it is not for any illegal purpose, customer wolud like to memorize GSM number of a client so he can get in touch with them.

هل كانت مفيدة؟

المحلول

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

Also requires the READ_PHONE_STATE permission to be in your manifest.

مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top