如何停止显示原生电话活动?

时间:2016-04-05 18:49:38

标签: android

背景

我们的团队正在开发一款需要能够通过个性化联系人列表拨打电话的应用。该应用程序还应该能够处理来自其活动内部的呼叫,而不是本地呼叫。

使用ITelephony界面,它已经能够打开/关闭扬声器和静音,也可以结束通话。问题是来自ITelephony的call()方法(进行调用的方法)需要受保护的权限,只有系统级应用才能访问它。

此时我们正在使用一种解决方法,我们使用Intent.ACTION_CALL进行调用,一旦调用开始,我们使用侦听NEW_OUTGOING_CALL的广播接收器将我们的调用活动置于本机之上。它可以工作,但是当我们进行调用时,屏幕上会弹出本机活动,然后才启动我们的活动,这看起来很糟糕。

接收器:

public class OutgoingCallReceiver extends BroadcastReceiver {
private static final String TAG = OutgoingCallReceiver.class.getSimpleName();

@Override
public void onReceive(Context context, Intent intent) {
    Log.i(TAG, "OutgoingCallReceiver CHAMADO");
    //abortBroadcast();

    Intent i = new Intent();
    i.setClass(context, CallingViewImpl.class);
    i.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);

    //waiting 1 second so the native activity won't pop up on top of our activity
    try {
        Thread.sleep(1000);
    } catch (InterruptedException e) {
        e.printStackTrace();
    }
    context.startActivity(i);
}
}

Here's a gif showing the flow, don't mind the alert error, it is because I was using a phone with no sim card.

问题

有没有阻止原生活动在不停止通话的情况下出现?或者是否有另一种解决这个问题的方法?

0 个答案:

没有答案