Android pjsip使用
时间: 2023-12-04 22:04:13 浏览: 195
以下是Android中使用pjsip的步骤:
1.下载pjsip库并解压缩。
2.在Android Studio中创建一个新项目。
3.将pjsip库中的pjlib、pjlib-util、pjnath、pjmedia、pjsip文件夹复制到您的项目的jni文件夹中。
4.在jni文件夹中创建一个Android.mk文件,内容如下:
```makefile
LOCAL_PATH := $(call my-dir)
include $(CLEAR_VARS)
# pjlib
PJLIB_VER := 2.7.2
PJLIB_PATH := $(LOCAL_PATH)/pjlib-$(PJLIB_VER)
# pjlib-util
PJLIB_UTIL_VER := 2.7.2
PJLIB_UTIL_PATH := $(LOCAL_PATH)/pjlib-util-$(PJLIB_UTIL_VER)
# pjnath
PJNATH_VER := 2.7.2
PJNATH_PATH := $(LOCAL_PATH)/pjnath-$(PJNATH_VER)
# pjmedia
PJMEDIA_VER := 2.7.2
PJMEDIA_PATH := $(LOCAL_PATH)/pjmedia-$(PJMEDIA_VER)
# pjsip
PJSIP_VER := 2.7.2
PJSIP_PATH := $(LOCAL_PATH)/pjsip-$(PJSIP_VER)
include $(PJLIB_PATH)/build.mak
include $(PJLIB_UTIL_PATH)/build.mak
include $(PJNATH_PATH)/build.mak
include $(PJMEDIA_PATH)/build.mak
include $(PJSIP_PATH)/build.mak
include $(CLEAR_VARS)
LOCAL_MODULE := pjsua2
LOCAL_SRC_FILES := pjsua2.cpp
LOCAL_C_INCLUDES := \
$(PJLIB_PATH)/include \
$(PJLIB_UTIL_PATH)/include \
$(PJNATH_PATH)/include \
$(PJMEDIA_PATH)/include \
$(PJSIP_PATH)/include
LOCAL_SHARED_LIBRARIES := \
libpjmedia-codec \
libpjmedia-videodev \
libpjmedia \
libpjsua2 \
libpjsip-ua \
libpjsip-simple \
libpjsip \
libpjnath \
libpjlib-util \
libpj \
libstdc++
include $(BUILD_SHARED_LIBRARY)
```
5.在jni文件夹中创建一个Application.mk文件,内容如下:
```makefile
APP_ABI := all
APP_PLATFORM := android-21
APP_STL := gnustl_static
```
6.在项目的build.gradle文件中添加以下代码:
```gradle
android {
...
defaultConfig {
...
ndk {
moduleName "pjsua2"
}
}
...
sourceSets.main {
jni.srcDirs = []
jniLibs.srcDir 'src/main/libs'
}
}
```
7.在项目的AndroidManifest.xml文件中添加以下代码:
```xml
<uses-permission android:name="android.permission.USE_SIP" />
<uses-feature android:name="android.hardware.sip.voip" />
```
8.在您的项目中创建一个Java类,例如MyPjsip.java,以实现pjsip的功能。
```java
public class MyPjsip {
static {
System.loadLibrary("pjsua2");
}
public native void init();
public native void makeCall(String uri);
public native void hangupCall();
public native void answerCall();
}
```
9.在您的项目中使用MyPjsip类来实现pjsip的功能。
```java
MyPjsip pjsip = new MyPjsip();
pjsip.init();
pjsip.makeCall("sip:1234567890@192.168.1.100");
pjsip.hangupCall();
pjsip.answerCall();
```
阅读全文