I use BroadcastReceiver to intercept incoming call on Android phone as below
tm = (TelephonyManager) context.getSystemService(Context.TELEPHONY_SERVICE);
Bundle bundle = intent.getExtras();
String number = bundle.getString(TelephonyManager.EXTRA_INCOMING_NUMBER);
In the "private number" case, I tested on two devices, it shows the number as -1 on HTC Wildfire and -2 on Galaxy S. I checked the android.telephony.PhoneNumberUtils
but it could't help me.
Is there a function or a generic way to detect a private number on Android phone?
You pretty much answered your own question. Private numbers are sent to the phone as -1 or -2. In my app I check for an integer value that is less than 0 and if it is, I treat it as a private number. This sounds like what you want to do as well.
I hope my thoughts are helpful.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With