4

I'm initiating new call from my activity. And trying to pass a boolean extra.

public class CallInitiatingActivity extends Activity {

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);

        Intent intent = new Intent(Intent.ACTION_CALL, Uri.parse("tel:" + number));
        intent.putExtra("com.demoapp.CUSTOM_CALL", true);
        startActivity(intent);
    }
}

I also have a BroadcastReceiver registered, which listens for outgoing calls:

<receiver android:name=".OutgoingCallListener" android:exported="true" >
    <intent-filter android:priority="0" >
        <action android:name="android.intent.action.NEW_OUTGOING_CALL" />
        <category android:name="android.intent.category.DEFAULT" />
    </intent-filter>
</receiver>

Basically what I'm expecting onReceive to see my extra, but somehow it is not passed:

public class OutgoingCallListener extends BroadcastReceiver {

    @Override
    public void onReceive(Context context, Intent intent) {
        Bundle extras = intent.getExtras();

        for (String key : extras.keySet()) {
            Log.i(Constant.LOG_TAG, key + ": " + extras.get(key));
        }
    }
}

Output:

android.phone.extra.ALREADY_CALLED:false
android.intent.extra.PHONE_NUMBER:+370652xxxxx
com.htc.calendar.event_uri:null
android.phone.extra.ORIGINAL_URI:tel:+370652xxxxx
Martynas Jurkus
  • 9,231
  • 13
  • 59
  • 101

1 Answers1

3

Your custom extra is present in the Intent that you use to start the "call" activity. But it isn't copied into the NEW_OUTGOING_CALL Intent that is broadcast as a part of the actual call mechanism. These 2 operations are distinct and only indirectly related to each other. Only the Android system itself can broadcast the NEW_OUTGOING_CALL Intent.

You can't add your own extras to this Intent. You'll need to come up with another way to do whatever it is you are trying to accomplish.

David Wasser
  • 93,459
  • 16
  • 209
  • 274
  • Than maybe You could offer solution to my problem? I must intercept initial user call and display an alert dialog, which must be displayed in activity and then initiate call again to the same number. So the problems is that both calls gets intercepted and I have no way to tell if call is made by user or by my application. – Martynas Jurkus Oct 08 '12 at 10:46
  • When you intercept the call, you can write the telephone number and the time of the interception into SharedPreference variables and put up the alert dialog. When the call is initiated again, you will intercept the call again and you can compare the telephone number against the saved phone number and compare the current time against the saved time (with some allowed variance like 60 seconds). If they are the same, you can skip the alert and make the call, if they are different you store the values in the SharedPreferences and put up the dialog again. – David Wasser Oct 08 '12 at 12:37
  • yeah, I thought about that, but is kinda hacky way :) I expected that there is a possibility to do this "Android way". – Martynas Jurkus Oct 08 '12 at 12:48
  • 1
    Android is just as hacky as every other platform. Some stuff is easy to do and some stuff you need to do by waving a dead chicken and saying the magic words "xyzzy" ;-) – David Wasser Oct 08 '12 at 12:50