基于linphone android sdk 的voip语音、视频通话 教程一、注册

如果觉得下面的麻烦可以直接到https://item.taobao.com/item.htm?id=587133228080获取源码。源码功能性更好、更完善。

想测试apk请加群261074724 

最新的sdk4教程地址  https://blog.csdn.net/Java_lilin/article/details/84842314

1.介绍

liblinphone官网除了提供了完整的源码下载外,还提供了liblinphone-android-sdk 的下载。由于源码复杂、难编译。。。,但你可以使用sdk开发。官网及网上的使用教程很少,所以我把他写出来 在之前需准备一台sip服务器  我用的freeswitch  

2.下载

sdk 下载地址http://www.linphone.org/technical-corner/liblinphone/downloads (http://www.linphone.org/technical-corner/liblinphone

下载安卓的sdk 就行了  不是下载源码大概15m左右吧

3. 解压拿到liblinphone-sdk.aar  由于是aar的 哎 。。这个是一个android studio的程序 如果你的开发平台是这个  你可以导入里面作为一个模块就行了 由于下载了个是最新的可以创建安卓8的 创建低版本的有各种蛋疼的问题所以放弃改用eclipse  非eclipse 可以跳过这段到4( 本文基于android5.1使用的 官网https://wiki.linphone.org/xwiki/wiki/public/view/Lib/Gettin提供了aar的使用)

  • 修改aar为zip
  •  解压到和到时候安卓工程同目录下
  • 把classes.jar和jni目录下的所有文件考到libs下
  • 删除jni目录
  • 创建project.properties 写入
  •        target=android-22
  •        android.library=true
  • 最后将工程导入eclipse
  • ok

4.创建android工程

这里创建一个android 5.1的项目

在引进sdk

出现红色的?那就是sdk和项目没在一个目录  eclipse bug

官网写了一个简单的使用说明

How to use the SDK

There is a documentation (javadoc)  of the methods wrapped above the linphone C layer to be used in your Android application available.

You can also download the source code of Linphone Android (see the Source Code part of this page) and take a look either at the LinphoneMini project in the sample/ folder or at the tutorials in the submodules/linphone/coreapi/help/java/org/linphone/core/tutorials/ folder.

看来还是要下载下源码(下载麻烦的可以到这里下载https://download.csdn.net/download/java_lilin/10452836 主要是不成功git  )

找这两个文件夹 sample/    submodules/linphone/coreapi/help/java/org/linphone/core/tutorials/  

把sample里面的res、xml的权限、src下的LinphoneMiniUtils.java  LinphoneMiniManager.java考到新建的工程

权限新增 <!--电池权限-->
     <uses-permission android:name="android.permission.WAKE_LOCK"/> 

<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />

在LinphoneMiniActivity.java里面的以下代码考到自己的activity里面

private LinphoneMiniManager mManager; 
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState); 

mManager = new LinphoneMiniManager(this);

....................................

protected void onDestroy() {
mManager.destroy(); 
super.onDestroy();

}

此时LinphoneMiniManager.java 出现报错

一个是没这个方法多了个@Override  另外是一个是少了一个string的参数  会java的都能改

最后在实现下没有实现的方法就不会有错了

ok  环境已经准备好了

5、开始注册  注册的时候就简单点击一个按钮 输出 注册成功

我们在activity_main.xml 里面添加

<TextView
        android:layout_width="wrap_content" 
        android:layout_height="wrap_content"
        android:id="@+id/id_text_status"
        android:textSize="20dip"

        android:text="注册状态" />

  <Button
           android:layout_marginTop="20dip"
           android:id="@+id/id_btn_reg"
           android:layout_width="match_parent"
           android:layout_height="wrap_content"

           android:text="注册" />

设置点击

  ((Button)this.findViewById(R.id.id_btn_reg)).setOnClickListener(this);

点击方法  (里面的就是sip地址、密码 、端口 )

String sipAddress="sip:[email protected]",password="12345"   

mManager.lilin_reg(sipAddress, password,"5060"); 

在LinphoneMiniManager.java添加

public void lilin_reg(String sipAddress,String password,String port) throws LinphoneCoreException{

LinphoneAddress address = lcFactory.createLinphoneAddress(sipAddress);
String username = address.getUserName();

String domain = address.getDomain(); 

LinphoneProxyConfig[] proxyConfigList = mLinphoneCore.getProxyConfigList();
for (LinphoneProxyConfig linphoneProxyConfig : proxyConfigList) {
mLinphoneCore.removeProxyConfig( linphoneProxyConfig);
}//删除原来的  

mLinphoneCore.addAuthInfo(lcFactory.createAuthInfo(username, password, null, domain+":"+port)); 
// create proxy config
LinphoneProxyConfig proxyCfg = mLinphoneCore.createProxyConfig(sipAddress, domain+":"+port, null, true);
proxyCfg.enablePublish(true);
proxyCfg.setExpires(2000);
mLinphoneCore.addProxyConfig(proxyCfg); // add it to linphone

mLinphoneCore.setDefaultProxyConfig(proxyCfg);//注册一次就好了  下次启动就不用注册

}

再到方法添加注册输出

@Override
public void registrationState(LinphoneCore lc, LinphoneProxyConfig cfg,
RegistrationState cstate, String smessage) {

Log.e("lilin Registration state: " + cstate + "(" + smessage + ")");

}

启动安卓测试点击按钮输出  lilin Registration state: xx(registered successfully)表示注册成功了 

未完待续  更多到博客列表

对此感兴趣的可以加群261074724 可免费下载东西哦哦哦哦哦

猜你喜欢

转载自blog.csdn.net/Java_lilin/article/details/80539116