简体   繁体   中英

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. 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. For some reason it is just always going with the else statement on his device. 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

Have you tried adding a Log to see the values of matchNumber and incomingNumber to check they do in fact match? Could be a case of +61 4### vs 04###?

Perhaps you also need to strip the values of incomingNumber with the regex as well?

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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