我正在尝试为voip调用实现ConnectionService。
注册电话帐户:
TelecomManager tm = (TelecomManager)
getSystemService(Context.TELECOM_SERVICE);
PhoneAccountHandle phoneAccountHandle = new
PhoneAccountHandle(
new ComponentName(getApplicationContext(),
ConnectionService33.class), "sample");
PhoneAccount phoneAccount =
PhoneAccount.builder(phoneAccountHandle, "sample")
.setShortDescription("sample")
.addSupportedUriScheme(PhoneAccount.SCHEME_TEL)
.setSupportedUriSchemes(Arrays.asList("tel"))
.setCapabilities(PhoneAccount.CAPABILITY_CALL_PROVIDER)
.setIcon(Icon.createWithResource(MainActivity.this,
R.drawable.ic_action_name))
.build();
tm.registerPhoneAccount(phoneAccount);
if (Build.MANUFACTURER.equalsIgnoreCase("Samsung")) {
Intent intent = new Intent();
intent.setComponent(new
ComponentName("com.android.server.telecom",
"com.android.server.telecom.settings.EnableAccountPreferenceActivity"));
startActivity(intent);
} else {
startActivity(new
Intent(TelecomManager.ACTION_CHANGE_PHONE_ACCOUNTS));
}
拨打电话:
TelecomManager tm = (TelecomManager)
getSystemService(Context.TELECOM_SERVICE);
PhoneAccountHandle phoneAccountHandle = new
PhoneAccountHandle(
new ComponentName(getApplicationContext(),
ConnectionService33.class), "sample");
Bundle extras = new Bundle();
Uri uri = Uri.fromParts(PhoneAccount.SCHEME_TEL,
"999999999", null);
extras.putParcelable(TelecomManager.EXTRA_OUTGOING_CALL_EXTRAS, uri);
extras.putParcelable(TelecomManager.EXTRA_INCOMING_CALL_ADDRESS, uri);
extras.putParcelable(TelecomManager.EXTRA_PHONE_ACCOUNT_HANDLE,
phoneAccountHandle);
//tm.addNewIncomingCall(phoneAccountHandle, extras);
tm.placeCall(uri, extras);
我的ConnectionService
@Override
public Connection onCreateIncomingConnection(PhoneAccountHandle
connectionManagerPhoneAccount, ConnectionRequest request) {
Log.d(TAG,"onCreateIncomingConnection");
Log.d(TAG,"incomong call = " + request.getAddress().toString());
TConnection tConnection = new TConnection(this);
tConnection.setAddress(request. getAddress(),TelecomManager.
PRESENTATION_ALLOWED);
tConnection.setAudioModeIsVoip(true);
tConnection.setConnectionCapabilities(Connection.CAPABILITY_MUTE);
tConnection.setInitializing();
return tConnection;
}
@Override
public Connection onCreateOutgoingConnection(PhoneAccountHandle
connectionManagerPhoneAccount, ConnectionRequest request) {
Log.d(TAG,"onCreateOutgoingConnection");
Log.d(TAG,"outgoing call = " + request.getAddress().toString());
TConnection tConnection = new TConnection(this);
tConnection.setAddress(request.getAddress(),TelecomManager.
PRESENTATION_ALLOWED);
tConnection.setAudioModeIsVoip(true);
tConnection.setConnectionCapabilities(Connection.CAPABILITY_MUTE);
tConnection.setInitializing();
return tConnection;
}
从应用程序放置传入和输出正常工作
当设备拨号盘(Nexus)中的单击拨号按钮
时在三星设备中单击拨号按钮 三星手机应用程序出错:不幸的是,手机已停止
D/InCallUtilsMultiSIM: getSimIconIndex: simidx =-1 returnValue-1
05-29 12:43:49.595 31474-31474/? D/AndroidRuntime: Shutting down VM
05-29 12:43:49.605 31474-31474/? E/AndroidRuntime: FATAL EXCEPTION: main
Process:
com.android.incallui,
PID: 31474
java.lang.ArrayIndexOutOfBoundsException: length=9; index=-1
at
com.android.incallui.InCallUtilsMultiSIM.
getSimImage(InCallUtilsMultiSIM.java:391)at
com.android.incallui.SelectPhoneSimAccountDialogFragment
$SelectAccountListAdapter.getView
(SelectPhoneSimAccountDialogFragment.java:154)
at
android.widget.AbsListView.obtainView(AbsListView.java:2929)
at
android.widget.ListView.measureHeightOfChildren(ListView.java:1305)
at
android.widget.ListView.onMeasure(ListView.java:1212)
at
android.view.View.measure(View.java:20151)