Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Android: how to detect a private number programmatically

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?

like image 714
Bao Le Avatar asked Jan 10 '11 18:01

Bao Le


1 Answers

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.

like image 131
Camille Sévigny Avatar answered Oct 12 '22 03:10

Camille Sévigny