简体   繁体   English

Android:如何以编程方式检测私人号码

[英]Android: how to detect a private number programmatically

I use BroadcastReceiver to intercept incoming call on Android phone as below 我使用BroadcastReceiver拦截Android手机上的来电,如下所示

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. 在“私人号码”的情况下,我测试了两个设备,它在HTC Wildfire上显示数字为-1,在Galaxy S上显示-2。我检查了android.telephony.PhoneNumberUtils但它无法帮助我。

Is there a function or a generic way to detect a private number on Android phone? 是否有功能或通用方法来检测Android手机上的私人号码?

You pretty much answered your own question. 你几乎回答了自己的问题。 Private numbers are sent to the phone as -1 or -2. 私人号码以-1或-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. 在我的应用程序中,我检查一个小于0的整数值,如果是,我将其视为私人号码。 This sounds like what you want to do as well. 这听起来像你想要做的。

I hope my thoughts are helpful. 我希望我的想法很有帮助。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM