Retrieve incoming call’s phone number in Android
Use PhoneStateListener. It has an onCallStateChanged handler; one of the supplied arguments you’ll get is a String containing the incoming phone number.
Use PhoneStateListener. It has an onCallStateChanged handler; one of the supplied arguments you’ll get is a String containing the incoming phone number.
Code: TelephonyManager tMgr = (TelephonyManager)mAppContext.getSystemService(Context.TELEPHONY_SERVICE); String mPhoneNumber = tMgr.getLine1Number(); Required Permission: <uses-permission android:name=”android.permission.READ_PHONE_STATE”/> Caveats: According to the highly upvoted comments, there are a few caveats to be aware of. This can return null or “” or even “???????”, and it can return a stale phone number that is no longer valid. If you want something … Read more
Capturing the outgoing call in a BroadcastReceiver has been mentioned and is definitely the best way to do it if you want to end the call before dialing. Once dialing or in-call, however, that technique no longer works. The only way to hang up that I’ve encountered so far, is to do so through Java … Read more