How to pass Extra to BroadcastReceiver when running ACTION_CALL

I initiate a new challenge from my activity. And trying to convey an extra boolean.

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 registered BroadcastReceiver that 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 expect onReceive to see my additional ones, but for some reason 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 
+4
source share
1 answer

Your custom emergency gift is present in the intent that you use to initiate the β€œcall” action. But it is not copied to NEW_OUTGOING_CALL Intent, which translates as part of the real call mechanism. These 2 operations are different and indirectly related to each other. Only Android can broadcast NEW_OUTGOING_CALL Intent.

You cannot add your own additions to this intention. You need to come up with another way to do what you are trying to accomplish.

+3
source

Source: https://habr.com/ru/post/1438245/


All Articles