如何使用connectionservice实现视频

时间:2017-03-30 06:50:45

标签: java android video

我想通过连接服务使用系统应用程序实现视频聊天。 https://developer.android.com/reference/android/telecom/ConnectionService.html。不幸的是我找不到任何示例或教程如何做到这一点。这就是我所做的:

注册服务:

TelecomManager manager = (TelecomManager) getSystemService(TELECOM_SERVICE);
PhoneAccountHandle phoneAccountHandle = new PhoneAccountHandle(new    ComponentName(getBaseContext().getPackageName(),    PhoneConnectionService.class.getName()), "myConnectionServiceId");
PhoneAccount.Builder builder = PhoneAccount.builder(phoneAccountHandle,   Localization.localize(R.string.IDS_APP_NAME_SHORT));
builder.setCapabilities(PhoneAccount.CAPABILITY_CALL_PROVIDER | PhoneAccount.CAPABILITY_CONNECTION_MANAGER| PhoneAccount.CAPABILITY_VIDEO_CALLING );
PhoneAccount phoneAccount = builder.build();
manager.registerPhoneAccount(phoneAccount);  

拨打电话:

TelecomManager manager = (TelecomManager) context.getSystemService(TELECOM_SERVICE);
PhoneAccountHandle phoneAccountHandle = new PhoneAccountHandle(new ComponentName(context.getPackageName(), PhoneConnectionService.class.getName()), "estosConnectionServiceId");
Bundle test = new Bundle();
test.putParcelable(TelecomManager.EXTRA_PHONE_ACCOUNT_HANDLE,phoneAccountHandle);
test.putInt(TelecomManager.EXTRA_START_CALL_WITH_VIDEO_STATE, VideoProfile.STATE_BIDIRECTIONAL);
test.putParcelable(TelecomManager.EXTRA_OUTGOING_CALL_EXTRAS,extras);
manager.placeCall(Uri.parse("tel:" + number),test);

我的ConnectionService被调用并且

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

    Connection conn = new MyAndroidCallConnection();
    conn.setAddress(request.getAddress(),PRESENTATION_ALLOWED);
    conn.setInitializing();
    conn.setVideoProvider(new MyVideoProvider());
    conn.setActive();

    return conn;
}

我将我的视频录像机放入系统要求的连接中。 电话活动出现并通过小相机标志向我显示呼叫,因此系统知道我想要做什么。 我现在以某种方式期望从系统调用videoprovider方法给我视频的表面等等但是没有方法被调用。 有人知道我做错了什么或知道在哪里找到这个主题的好例子。

1 个答案:

答案 0 :(得分:0)

我只是忘了将AcceptsReturn = True添加到我的连接中,而不仅仅是在placeCall上。现在按预期访问VideoProvider