我正在尝试使用原生
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生成的Log中的内容
@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);
}
}
最佳答案 我将MyConnectionService重命名为MyService – 开始工作.奇怪的!