Search code examples
javaandroidandroid-intentbroadcastreceiver

Change the number for outgoing call, add prefix


According to this blogpost on android developers blog it should be doable to change an outgoing call number: http://android-developers.blogspot.com/2011/01/processing-ordered-broadcasts.html

The problem is that it doesn't work for me, my code:

String action = intent.getAction();
if (Intent.ACTION_NEW_OUTGOING_CALL.equals(action)) {
    // Try to read the phone number from previous receivers.
    String phonenumber = getResultData();

    if (phonenumber == null) {
        // We could not find any previous data. Use the original
        // phone
        // number in this case.
        phonenumber = intent
                .getStringExtra(Intent.EXTRA_PHONE_NUMBER);
    }

        String reformatedNumber = reformatNumber(phonenumber);
    setResultData(reformatedNumber);                                
}

Even though I reformat the number the phone number i dialed is the one being called up.

Any insight?

I have these permissions in my manifest:

<uses-permission android:name="android.permission.PROCESS_OUTGOING_CALLS" />
<uses-permission android:name="android.permission.CALL_PHONE" />
<uses-permission android:name="android.permission.CALL_PRIVILEGED" />

The weird thig is that when I call I number that is not stored in the phone book I have a service that tries to figure out who I'm calling and I have to press a "Call" button on a dialog to complete the call. Then my code works, but when I call someone from the phonebook or if i disable the look-up service it doesn't work.


Solution

  • From the blogpost you mention:

    We have actually observed phones with a priority 0 receiver for the NEW_OUTGOING_CALL intent installed out of the box (this will be the last one that is called after all others) that completely ignores previous result data which means that, in effect, they disable any useful processing of ACTION_NEW_OUTGOING_CALL (other than canceling the call, which would still work). The only workaround for this is to also run your receiver at priority 0, which works due to particularities of running 2 receivers at the same priority but, by doing that, you break one of the few explicit rules for processing outgoing calls:

    “For consistency, any receiver whose purpose is to prohibit phone calls should have a priority of 0, to ensure it will see the final phone number to be dialed. Any receiver whose purpose is to rewrite phone numbers to be called should have a positive priority. Negative priorities are reserved for the system for this broadcast; using them may cause problems.”

    Is it possible that you are running into the fact that on a handset you're code is being ignored by an intent installed by the provider at priority 0? You can test this by setting your priority to 0 as well.