使用自定义ConnectionService和PhoneAccount时,呼出电话不响铃

4
我正在开发一个钩子到股票拨号器(Marshmallow API)的应用程序。我的目标是在获取来电和拨出电话的同时,掌握 Connection对象以操作连接的方法。
我已经注册了PhoneAccount并具备了CAPABILITY_CALL_PROVIDER
PhoneAccount.Builder builder = new PhoneAccount.Builder(phoneAccountHandle, "CustomAccount");
builder.setCapabilities(PhoneAccount.CAPABILITY_CALL_PROVIDER);
PhoneAccount phoneAccount = builder.build();
telecomManager.registerPhoneAccount(phoneAccount);

我的账户在股票拨号器应用程序内可见(设置->通话->呼叫帐户),我已启用它。

我有一个服务来监视电话状态,在CALL_STATE_RINGING时调用TelecomManager的addNewIncomingCall()方法。

public void onCallStateChanged(int state, String incomingNumber) {
    if (state == TelephonyManager.CALL_STATE_RINGING) {
        Toast.makeText(getApplicationContext(), "Phone Is Ringing",
                Toast.LENGTH_SHORT).show();
        Bundle extras = new Bundle();
        Uri uri = Uri.fromParts(PhoneAccount.SCHEME_TEL, incomingNumber, null);
        extras.putParcelable(TelecomManager.EXTRA_INCOMING_CALL_ADDRESS, uri);
        extras.putParcelable(TelecomManager.EXTRA_PHONE_ACCOUNT_HANDLE, phoneAccountHandle);
        telecomManager.addNewIncomingCall(phoneAccountHandle, extras);
    }
    if (state == TelephonyManager.CALL_STATE_OFFHOOK) {.......}
    ...
} 

我的自定义连接服务

@Override
public Connection onCreateIncomingConnection(PhoneAccountHandle connectionManagerPhoneAccount, ConnectionRequest request) {

    Toast.makeText(getApplicationContext(), "onCreateIncomingConnection called", Toast.LENGTH_SHORT).show();
    Connection incomingCallCannection = createConnection(request);
    incomingCallCannection.setRinging();
    return incomingCallCannection;
}

@Override
public Connection onCreateOutgoingConnection(PhoneAccountHandle connectionManagerPhoneAccount, ConnectionRequest request) {
    Toast.makeText(getApplicationContext(), "onCreateOutgoingConnection called", Toast.LENGTH_SHORT).show();

    Connection outgoingCallConnection = createConnection(request);
    outgoingCallConnection.setDialing();

    return outgoingCallConnection;
}

private Connection createConnection(ConnectionRequest request) {
    mConnection = new Connection() {
        @Override
        public void onStateChanged(int state) {
            super.onStateChanged(state);
        }

        @Override
        public void onDisconnect() {
            super.onDisconnect();
            mConnection.setDisconnected(new DisconnectCause(DisconnectCause.CANCELED));
            mConnectionsAvailableForConference.clear();
            mConnection.destroy();
        }

        @Override
        public void onSeparate() {
            super.onSeparate();
        }

        @Override
        public void onAbort() {
            super.onAbort();
            mConnection.setDisconnected(new DisconnectCause(DisconnectCause.CANCELED));
            mConnection.destroy();
        }

        @Override
        public void onHold() {
            super.onHold();
        }

        @Override
        public void onAnswer() {
            super.onAnswer();
            mConnection.setActive();
        }

        @Override
        public void onReject() {
            super.onReject();
            mConnection.setDisconnected(new DisconnectCause(DisconnectCause.CANCELED));
            mConnection.destroy();

        }
    };
    mConnection.setAddress(request.getAddress(), TelecomManager.PRESENTATION_ALLOWED);
    mConnection.setExtras(request.getExtras());
    return mConnection;
}

现在,ConnectionService的回调方法分别在呼入和呼出通话时都被调用。问题是,当我进入拨号器并拨打一个外部电话(使用我的PhoneAccount)时,我会看到拨号屏幕(在通话UI中?),正确的呼叫者信息被显示出来(联系人姓名、电话号码等),但是我的听筒里没有响铃声,通话也没有建立(应该接收呼叫的电话号码也没有响铃)。我尝试在回调中返回super.onCreateOutgoingConnection(PhoneAccountHandle connectionManagerPhoneAccount, ConnectionRequest request)而不是创建自己的Connection对象,但我得到了相同的行为。简而言之:我的应用程序与拨号器通信,能够拨打电话并显示拨号屏幕,但电话线路没有响铃,什么也没有发生。
1个回答

0

我已经在这上面花了好几天的时间寻找解决方案。但是在再次阅读文档后,它清楚地说明使用自定义电话帐户进行呼出不会使用手机sim服务进行呼叫,应用程序将独立处理所有呼叫操作。

CAPABILITY_CALL_PROVIDER:指示此PhoneAccount可以代替传统基于SIM的电话呼叫进行电话呼叫的标志。

如果您需要在呼出通话期间传输数据,可以使用Bundle将信息发送到默认的呼叫应用程序。

您可以在此处阅读更多文档。 https://developer.android.com/reference/android/telecom/PhoneAccount https://developer.android.com/guide/topics/connectivity/telecom/selfManaged#outgoing


网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接