如何通过群众演员到一个BroadcastReceiver [英] How to pass extras to a BroadcastReceiver

查看:98
本文介绍了如何通过群众演员到一个BroadcastReceiver的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个问题,路过群众演员呼叫,追赶他们。

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

为了更清楚我打算做的:

To make more clear what I intend to do:

开始一个电话,临时演员这个意图。这就是我目前的code这个样子:

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

Intent dialIntent=new Intent(Intent.ACTION_CALL, Uri.parse("tel:" +  this.number));
dialIntent.putExtra("foo", true);
startActivity(dialIntent);

我实现一个BroadcastReceiver来抓的号召,并要访问我在开始活动时,设置多余的。这是我在我的清单:

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>

不幸的是,传递给我CallReceiver的意图是一个NEW_OUTGOING_CALL意图。

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.

在此先感谢。

推荐答案

而不是使用BroadcastReciever在这里你真的想再拍默认拨号器的活动,但是这其中将有一个更高的优先级,以确保它会前推出原生拨号器应用程序。然后,你可以改变这样的意图:

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!

这篇关于如何通过群众演员到一个BroadcastReceiver的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆