【发布时间】:2017-11-30 10:56:39
【问题描述】:
我正在尝试实现 ConnectionService、PhoneAccount 和 PhoneAccountHandle,以便获取我的拨出呼叫断开的 disconnectCause(例如,用户拒绝呼叫、无法接通等) 到目前为止,我已经能够使用 customPhoneAccount 发起呼叫,但该电话从未接通,因此我无法得到响应。
这是我到目前为止编写的代码:
register() 是从我的活动中调用来注册 phoneAccount 的方法:
public void register() {
TelecomManager manager = (TelecomManager) getSystemService(TELECOM_SERVICE);
PhoneAccountHandle phoneAccountHandle = new PhoneAccountHandle(
new ComponentName(getPackageName(),
MyConnectionService.class.getName()), "myConnectionServiceId");
PhoneAccount.Builder builder = PhoneAccount.builder(phoneAccountHandle, "CustomAccount");
builder.setCapabilities(PhoneAccount.CAPABILITY_CALL_PROVIDER | PhoneAccount.CAPABILITY_CONNECTION_MANAGER);
PhoneAccount phoneAccount = builder.build();
manager.registerPhoneAccount(phoneAccount);
}
call() 方法发起调用:
public void call() {
TelecomManager manager = (TelecomManager) getSystemService(TELECOM_SERVICE);
PhoneAccountHandle phoneAccountHandle = new PhoneAccountHandle(
new ComponentName(getPackageName(),
MyConnectionService.class.getName()), "myConnectionServiceId");
Bundle test = new Bundle();
test.putParcelable(TelecomManager.EXTRA_PHONE_ACCOUNT_HANDLE, phoneAccountHandle);
manager.placeCall(Uri.parse("tel:" + "1212312312"), test);
}
这是我的连接服务:
public class MyConnectionService extends ConnectionService {
public static final String TAG = MyConnectionService.class.getName();
@Override
public int onStartCommand(Intent intent,int flags, int startId) {
Log.d(TAG, "On Start");
return super.onStartCommand(intent, flags, startId);
}
@Override
public Connection onCreateOutgoingConnection(PhoneAccountHandle connectionManagerPhoneAccount, ConnectionRequest request) {
Connection connection = super.onCreateOutgoingConnection(connectionManagerPhoneAccount, request);
Log.d(TAG, connection.getDisconnectCause().getReason());
return connection;
}
@Override
public void onCreateOutgoingConnectionFailed(PhoneAccountHandle connectionManagerPhoneAccount, ConnectionRequest request) {
if (request != null) {
Log.d(TAG, request.toString());
}
super.onCreateOutgoingConnectionFailed(connectionManagerPhoneAccount, request);
}
我尝试了不同的功能以及与 ConnectionService 相关的其他线程中提到的所有选项,但无法获得所需的结果,有人可以帮助我吗?
【问题讨论】:
-
你能实现它吗?我只能使用 ConnectionService 进行虚假/虚拟通话,但我需要能够进行实际通话。检查了Android源代码,看起来有很多事情需要做。我知道应该有更好的方法。
-
@artsylar:不,我无法让它工作,我不确定过去两年左右情况是否发生了变化,但当时很明显,Android 不允许“获取我的拨出电话断开的 disconnectCause"
-
@Saurabh7474 我坚持实现 connectionService API。您能否提供一些集成连接服务的示例。
标签: android android-6.0-marshmallow phone-call