[英]Android Call Filter working on my device, but not client's device
I have created a simple call filter using a for loop that goes through a database and searches for a saved number. 我使用for循环创建了一个简单的调用过滤器,该循环遍历数据库并搜索保存的号码。 This filter works great on my device, but when I send it to my client, it automatically allows every call to go through.
该过滤器在我的设备上很好用,但是当我将其发送给客户端时,它会自动允许每个呼叫通过。 The filter is showing the "Deflecktur allowed a call from ...", so I know that we are getting to the if/else statement.
筛选器显示“ Deflecktur允许来自...的调用”,因此我知道我们将进入if / else语句。 For some reason it is just always going with the else statement on his device.
由于某种原因,它总是与设备上的else语句一起使用。 Here is the code from the broadcast receiver.
这是来自广播接收器的代码。
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();
}
}
}
}
The client is using a Samsung Galaxy Light, and I am using a OnePlus One 客户端正在使用Samsung Galaxy Light,而我正在使用OnePlus One
Have you tried adding a Log to see the values of matchNumber and incomingNumber to check they do in fact match? 您是否尝试过添加日志以查看matchNumber和incomingNumber的值以检查它们是否确实匹配? Could be a case of +61 4### vs 04###?
可能是+61 4 ### vs 04 ###的情况吗?
Perhaps you also need to strip the values of incomingNumber with the regex as well? 也许您还需要用正则表达式剥离传入的值?
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.