如何通过额外的BroadcastReceiver来,开始的时候ACTION_CALL [英] How to pass Extra to BroadcastReceiver, when initiating ACTION_CALL
问题描述
我开始从我的活动新的呼叫。并试图通过一个布尔额外的费用。
公共类CallInitiatingActivity延伸活动{ @覆盖
保护无效的onCreate(捆绑savedInstanceState){
super.onCreate(savedInstanceState); 意向意图=新意图(Intent.ACTION_CALL,Uri.parse(电话:+号));
intent.putExtra(com.demoapp.CUSTOM_CALL,真正的);
startActivity(意向);
}
}
我也有注册一个BroadcastReceiver,它监听打出的电话:
<接收机器人:OutgoingCallListenerNAME =机器人:出口=真正的>
<意向过滤器的android:优先=0>
<作用机器人:名字=android.intent.action.NEW_OUTGOING_CALL/>
<类机器人:名字=android.intent.category.DEFAULT/>
&所述; /意图滤光器>
< /接收器>
基本上我期待的onReceive看到我的额外费用,但不知何故,不通过:
公共类OutgoingCallListener扩展广播接收器{ @覆盖
公共无效的onReceive(上下文的背景下,意图意图){
捆绑额外= intent.getExtras(); 对于(字符串键:extras.keySet()){
Log.i(Constant.LOG_TAG,键+:+ extras.get(键));
}
}
}
输出:
android.phone.extra.ALREADY_CALLED:假的
android.intent.extra.PHONE_NUMBER:+ 370652xxxxx
com.htc.calendar.event_uri:空
android.phone.extra.ORIGINAL_URI:电话:+ 370652xxxxx
您定制额外的是您用来启动呼活动意向present。但它不会复制到广播作为实际调用机制的一部分 NEW_OUTGOING_CALL
意图。这些2操作是不同的,只有间接彼此相关。只有Android系统本身可以播放 NEW_OUTGOING_CALL
意图。
您不能添加自己的额外这种意图。你需要想出另一种方式来做到不管它是你所要完成的。
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
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.
这篇关于如何通过额外的BroadcastReceiver来,开始的时候ACTION_CALL的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!