문제

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.

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top