androidtelephony

Receive Phone Number from Phone Call


I'm looking to make a customized phone log and was wondering if there was some kind of built-in Android library that lets your app receive phone calls and then get the phone number or data from the phone call. That way I can store it in my customized phone log.


Solution

  • You should use Android's Telephony Manager for this:

    https://developer.android.com/reference/android/telephony/TelephonyManager.html

    You need to hook your application up to the ACTION_PHONE_STATE_CHANGED intent. The intent comes with a few extras, and one of them is EXTRA_INCOMING_NUMBER -- which contains the phone # as a string.

    This site has a pretty good example:

    https://web.archive.org/web/20210127130519/http://www.tutorialforandroid.com/2009/01/get-phone-state-when-someone-is-calling_22.html