我尝试使用原生Android来电UI。我已经获得了connectionService,并且我已经成功注册了一个电话帐户。但是在我调用方法addNewIncomingCall之后什么也没发生。我错过了哪些想法?
...清单
<service
android:name=".MyConnectionService"
android:label="example"
android:permission="android.permission.BIND_TELECOM_CONNECTION_SERVICE">
<intent-filter>
<action android:name="android.telecom.ConnectionService"/>
</intent-filter>
</service>
...活性
TelecomManager tm = (TelecomManager) getSystemService(Context.TELECOM_SERVICE);
if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.M) {
PhoneAccountHandle phoneAccountHandle = new PhoneAccountHandle(
new ComponentName(this.getApplicationContext(), MyConnectionService.class),
"example");
PhoneAccount phoneAccount = PhoneAccount.builder(phoneAccountHandle, "example").setCapabilities(PhoneAccount.CAPABILITY_CALL_PROVIDER).build();
tm.registerPhoneAccount(phoneAccount);
Bundle extras = new Bundle();
Uri uri = Uri.fromParts(PhoneAccount.SCHEME_TEL, mNumber.getText().toString(), null);
extras.putParcelable(TelecomManager.EXTRA_INCOMING_CALL_ADDRESS, uri);
extras.putParcelable(TelecomManager.EXTRA_PHONE_ACCOUNT_HANDLE, phoneAccountHandle);
tm.addNewIncomingCall(phoneAccountHandle, extras);
}
MyConnectionService,我希望至少能看到onCreateIncomingConnection生成的日志中的内容
@RequiresApi(api = Build.VERSION_CODES.M)
public class MyConnectionService extends ConnectionService {
private static String TAG = "MyConnectionService";
public MyConnectionService() {
}
@Override
public Connection onCreateIncomingConnection(PhoneAccountHandle connectionManagerPhoneAccount, ConnectionRequest request) {
Log.i(TAG,"onCreateIncomingConnection");
return super.onCreateIncomingConnection(connectionManagerPhoneAccount, request);
}
}
答案 0 :(得分:1)
我将MyConnectionService重命名为MyService - 开始工作。怪异!
答案 1 :(得分:0)
不知道您是否仍然需要答案,但是也许您应该尝试初始化CallConnection。
@Override
public Connection onCreateIncomingConnection(PhoneAccountHandle
connectionManagerPhoneAccount, ConnectionRequest request) {
CallConnection callConnection = new CallConnection();
callConnection.setInitializing();
return callConnection;
}
然后,您可以创建CallConnection的子类,该子类扩展Connection并调用onAnswer()方法。
@TargetApi(Build.VERSION_CODES.O)
public class CallConnection extends Connection{
public CallConnection(){
setConnectionProperties(PROPERTY_SELF_MANAGED);
setAudioModeIsVoip(true);
}
@Override
public void onAnswer(){
Log.d(TAG, "onAnswer() called");
//Accept the Call
}
}
不确定是否需要这些属性,但可以尝试一下!