gradle
中引用lib文件implementation files('libs/i22call-sdk-release.aar')
<uses-permission android:name="android.permission.INTERNET" /> <!-- 语音通话权限 -->
<uses-permission android:name="android.permission.RECORD_AUDIO" /> <!-- 免提权限 -->
<uses-permission android:name="android.permission.MODIFY_AUDIO_SETTINGS" />
Core mLinPhoneCore;
Factory lcFactory = Factory.instance();
lcFactory.setDebugMode(true, "lilinaini 34>>");
String basePath = mContext.getFilesDir().getAbsolutePath();
mLinPhoneCore = lcFactory.createCore(basePath + "/.linphonerc", basePath + "/linphonerc", mContext);
mLinPhoneCore.enableAdaptiveRateControl(false);
mLinPhoneCore.start();
使用时注意先清空之前的资源
AccountBuilder builder = new AccountBuilder(mLinPhoneCore)
.setUsername(username)
.setDomain(domain + ":" + port)
.setHa1(null)
.setUserid(username)
.setDisplayName("")//显示名
.setPassword(password);
builder.setAvpfEnabled(false);
if (prefix != null) {
builder.setPrefix(prefix);
}
String forcedProxy = "";//
if (!TextUtils.isEmpty(forcedProxy)) {
builder.setServerAddr(forcedProxy).setOutboundProxyEnabled(true);// .setAvpfRrInterval(5);
}
if (transport != null) {
builder.setTransport(transport);
}
try {
builder.saveNewAccount();
} catch (CoreException e) {
Log.e("tishi", ">>>>" + e.getMessage());
}
Call.inviteAddressWithParams()
//使用可以参考
public void callOut(String username, String host, boolean isVideoCall) {
if (mLinPhoneCore == null) {
return;
}
Address address = mLinPhoneCore.interpretUrl(username + "@" + host);
address.setDisplayName(username);
CallParams params = mLinPhoneCore.createCallParams(null);
//params.enableLowBandwidth(true);
// params.setAudioBandwidthLimit(0);//
params.enableVideo(isVideoCall);
Call call = mLinPhoneCore.inviteAddressWithParams(address, params);
if (call == null) {
Log.e("lilin error", "Could not place call to " + username);
return;
}
}
Call.sendDtmf()
//注意这里的Call对象要拿到当前呼叫的Call对象
//可以参考
mLinPhoneCore.getLC().setUseInfoForDtmf(true);
Call currentCall = instance.getLC().getCurrentCall();
if (currentCall != null && !TextUtils.isEmpty(input)) {
char a = input.charAt(0);
currentCall.sendDtmf(msg);
}
Call.terminateAllCalls();
在初始化时注册CoreListener监听,并注意其中的onRegistrationStateChanged()和onCallStateChanged()回调方法
onRegistrationStateChanged主要返回注册信息的回调
onCallStateChanged主要返回呼叫状态的回调