【问题标题】:Initiate new phone call from BroadcastReceiver从 BroadcastReceiver 发起新的电话呼叫
【发布时间】:2012-10-04 16:16:46
【问题描述】:

我正在用我的BroadcastReceiver 监听拨出电话。

当发出某个呼叫时,满足特定号码和/或条件 - 没关系,我会拦截呼叫。

之后,我想拨一个新电话到另一个号码。在这里我遇到了麻烦。未发出呼叫 - 没有任何反应 - 新活动已启动,但未启动呼叫。空视图,仅此而已。

通过BroadcastReceiver接收intent的方式,然后CallInitiatingActivity.onCreate()被调用并执行。

广播听众

public class OutgoingCallListener extends BroadcastReceiver {

    @Override
    public void onReceive(Context context, Intent intent) {
        if (conditionsAreMet()) {
            setResultData(null); //terminate current call
            Inetent intent = new Intent(context, CallInitiatingActivity.class)
            intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_CLEAR_WHEN_TASK_RESET);
            startActivity(intent);
        }
    }
}

呼叫发起活动

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));
        startActivity(intent);
    }
}

使用的权限:

<uses-permission android:name="android.permission.CALL_PHONE"/>

调试级别的可疑登录:

checkAndCopyPhoneProviderExtras: some or all extras are missing.

我在第 2074 行追踪到 this class 中的方法。

【问题讨论】:

  • 用“可疑日志”更新问题

标签: android


【解决方案1】:

您可能需要确保您拥有正确的权限:

<uses-permission android:name="android.permission.CALL_PHONE"></uses-permission>

可能会有所帮助

intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);

到目的。

【讨论】:

  • 对不起,我忘了提,我已经添加了所需的权限,并且代码中使用了标志。我会用正确的信息更新问题。
【解决方案2】:

像这样在 Manifest.xml 中为 BroadcastReceiver 类定义操作

 <receiver android:name="yourBroadcastReceiverpackagename.BroadcastReceiverclassname" 
       android:exported="false">
 <intent-filter>
 <action 
       android:name="Declare your Action name here"/>
 </intent-filter>

【讨论】:

  • 定义动作是什么意思?我必须制作另一个广播接收器吗?
  • 不,你必须在 Manifest.xml 文件中添加你的 BroadcastReceiver 类
  • 嗯。也许我的问题不清楚 - 我打断了我原来的电话,但没有拨打另一个电话。我的 BroadcastReceiver (OutgoingCallListener) 在 Manifest.xml 中声明
【解决方案3】:

问题中的代码正常发起新呼叫。 但我看不到这一点,因为 BroadcastReceiver 通过NEW_OUTGOING_CALL 操作接收意图。

那是当我创建ACTION_CALL 并添加额外内容以识别我手动创建了一个调用,该调用使用NEW_OUTGOING_CALL 操作将意图“转换”为另一个意图。这种方式有效地失去了所有额外的东西。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2012-09-19
    • 2020-08-15
    • 1970-01-01
    • 2023-03-21
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多