开发者

How to pass extras to a BroadcastReceiver

I have a problem with passing extras to calls and catching them.

To make more clear what I intend to do:

Start a call and set extras for this intent. This is what my current code for this looks like:

Intent dialIntent=new Intent(Intent.ACT开发者_如何学编程ION_CALL, Uri.parse("tel:" +  this.number));
dialIntent.putExtra("foo", true);
startActivity(dialIntent);

I implement a BroadcastReceiver to "catch" the call and want to access the extra I set when starting the activity. This is what I have in my manifest:

<receiver android:name=".CallReceiver">
  <intent-filter android:priority="1">
    <action android:name="android.intent.action.NEW_OUTGOING_CALL" />
  </intent-filter>
</receiver>

Unfortunately the intent that is passed to my CallReceiver is a NEW_OUTGOING_CALL intent.

I hope it's clear what I want to do and I hope it is possible.

Thanks in advance.


Rather than using a BroadcastReciever here you actually want to make another 'default dialer' activity but this one will have a higher priority to ensure it will be launched before the native dialer app. Then you can alter the intent like this:

public void onCreate(Bundle b){
    Intent i = getIntent();
    //alter i here 
    startNextMatchingActivity(i);
}

hope this helps!

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜