我使用for循环创建了一个简单的调用过滤器,该循环遍历数据库并搜索已保存的数字。此过滤器在我的设备上运行良好,但当我将其发送到我的客户端时,它会自动允许每个呼叫通过。过滤器显示“Deflecktur允许来自...的呼叫”,所以我知道我们正在进入if / else语句。出于某种原因,它总是在他的设备上使用else语句。这是来自广播接收器的代码。
if (blocker && isRunning) {
String appName = context.getString(R.string.app_name);
ITelephony telephonyService = getTeleService(context);
if (telephonyService != null) {
SparseArray<Phone> phones = getPhones(context, false);
String incomingNumber = null;
try {
incomingNumber = intent.getExtras().getString(
TelephonyManager.EXTRA_INCOMING_NUMBER);
if (incomingNumber != null && phones != null && phones.size() > 0) {
Log.i(TAG, "incoming call from " + incomingNumber);
boolean reject = false;
for (int i = 0; i < phones.size(); i++) {
Phone phone = phones.valueAt(i);
// Remove various characters to ensure a match
String matchNumber;
matchNumber = phone.getPhoneNumber().replaceAll("[^0-9\\+.,;#\\*N]", "");
if (incomingNumber.equals(matchNumber)) {
reject = true;
break;
}
}
if (reject) {
if (VERSION.SDK_INT < VERSION_CODES.GINGERBREAD) {
// Old method of silencing the ringer
telephonyService.silenceRinger();
} else {
final AudioManager am = (AudioManager) context
.getSystemService(Context.AUDIO_SERVICE);
if (am.getRingerMode() != AudioManager.RINGER_MODE_SILENT) {
// Silence the ringer
if (mThread == null || !mThread.isAlive()) {
mRingerMode = am.getRingerMode();
}
am.setRingerMode(AudioManager.RINGER_MODE_SILENT);
mThread = new Thread() {
public void run() {
SystemClock.sleep(3000);
am.setRingerMode(mRingerMode);
};
};
mThread.start();
}
}
telephonyService.endCall();
Toast.makeText(context, appName + " rejecting call from " + incomingNumber,
Toast.LENGTH_LONG).show();
Log.i(TAG, "call ended");
} else {
Toast.makeText(context, appName + " accepted call from " + incomingNumber,
Toast.LENGTH_LONG).show();
Log.i(TAG, "call accepted");
}
} else {
// A phone state was encountered without incoming number, e.g. an outgoing call; ignore
}
} catch (Exception e) {
if (incomingNumber == null)
incomingNumber = "[unknown]";
e.printStackTrace();
Log.e(TAG, "failed getting call info", e);
Toast.makeText(
context, appName + " failed rejecting call from " + incomingNumber + "\n"
+ e.getMessage(),
Toast.LENGTH_LONG).show();
}
}
}
}
客户正在使用三星Galaxy Light,而我正在使用OnePlus One
答案 0 :(得分:0)
您是否尝试添加日志以查看matchNumber和incomingNumber的值以检查它们确实匹配?可能是+61 4 ### vs 04 ###?
的情况也许您还需要使用正则表达式去除incomingNumber的值?