首先上一段自己的程序中的代码片段,然后再借用别人的一些帖子内容和说明来完善。
Engine.getInstance().getConfigurationService().putBoolean(NgnConfigurationEntry.GENERAL_AUTOSTART, true);
startMyService();
startMyService()的代码
private void startMyService() {
final Engine engine = (Engine) Engine.getInstance();
Thread thread = new Thread(new Runnable() {
@Override
public void run() {
if (!engine.isStarted()) {
engine.start();
}
}
});
thread.setPriority(Thread.MAX_PRIORITY);
thread.start();
}
Engine的代码
public class Engine extends NgnEngine{
private final static String TAG = Engine.class.getCanonicalName();
private static final String CONTENT_TITLE = "IMSDroid";
private static final int NOTIF_AVCALL_ID = 19833892;
private static final int NOTIF_SMS_ID = 19833893;
private static final int NOTIF_APP_ID = 19833894;
private static final int NOTIF_CONTSHARE_ID = 19833895;
private static final int NOTIF_CHAT_ID = 19833896;
private IScreenService mScreenService;
public static NgnEngine getInstance(){
if(sInstance == null){
sInstance = new Engine();
}
return sInstance;
}
public Engine(){
super();
}
@Override
public boolean start() {
return super.start();
}
@Override
public boolean stop() {
return super.stop();
}
private void showNotification(int notifId, int drawableId, String tickerText) {
if(!mStarted){
return;
}
// Set the icon, scrolling text and timestamp
final Notification notification = new Notification(drawableId, "", System.currentTimeMillis());
Intent intent = new Intent(PocApplication.getContext(), GroupPersonal.class);
intent.setFlags(Intent.FLAG_ACTIVITY_SINGLE_TOP | Intent.FLAG_ACTIVITY_NEW_TASK);
LogUtils.d("lijia", "Engine 通知栏点击");
switch(notifId){
case NOTIF_APP_ID:
notification.flags |= Notification.FLAG_ONGOING_EVENT;
intent.putExtra("notif-type", "reg");
break;
case NOTIF_CONTSHARE_ID:
intent.putExtra("action", MainActivity.ACTION_SHOW_CONTSHARE_SCREEN);
notification.defaults |= Notification.DEFAULT_SOUND;
break;
case NOTIF_SMS_ID:
notification.flags |= Notification.FLAG_AUTO_CANCEL;
notification.defaults |= Notification.DEFAULT_SOUND;
notification.tickerText = tickerText;
intent.putExtra("action", MainActivity.ACTION_SHOW_SMS);
break;
case NOTIF_AVCALL_ID:
tickerText = String.format("%s (%d)", tickerText, NgnAVSession.getSize());
intent.putExtra("action", MainActivity.ACTION_SHOW_AVSCREEN);
break;
case NOTIF_CHAT_ID:
notification.defaults |= Notification.DEFAULT_SOUND;
tickerText = String.format("%s (%d)", tickerText, NgnMsrpSession.getSize(new NgnPredicate<NgnMsrpSession>() {
@Override
public boolean apply(NgnMsrpSession session) {
return session != null && NgnMediaType.isChat(session.getMediaType());
}
}));
intent.putExtra("action", MainActivity.ACTION_SHOW_CHAT_SCREEN);
break;
default:
break;
}
PendingIntent contentIntent = PendingIntent.getActivity(PocApplication.getContext(), notifId/*requestCode*/, intent, PendingIntent.FLAG_UPDATE_CURRENT);
// Set the info for the views that show in the notification panel.
notification.setLatestEventInfo(PocApplication.getContext(), CONTENT_TITLE, tickerText, contentIntent);
// Send the notification.
// We use a layout id because it is a unique number. We use it later to cancel.
mNotifManager.notify(notifId, notification);
}
/**显示 是否连接通知,改变原点状态*/
public void showAppNotif(int drawableId, String tickerText){
Log.d(TAG, "showAppNotif");
showNotification(NOTIF_APP_ID, drawableId, tickerText);
}
/**显示电话打入与收到的状态*/
public void showAVCallNotif(int drawableId, String tickerText){
showNotification(NOTIF_AVCALL_ID, drawableId, tickerText);
}
/**显示 是否连接通知,改变原点状态*/
public void cancelAVCallNotif(){
if(!NgnAVSession.hasActiveSession()){
mNotifManager.cancel(NOTIF_AVCALL_ID);
}
}
public void refreshAVCallNotif(int drawableId){
if(!NgnAVSession.hasActiveSession()){
mNotifManager.cancel(NOTIF_AVCALL_ID);
}
else{
showNotification(NOTIF_AVCALL_ID, drawableId, "In Call");
}
}
public void showContentShareNotif(int drawableId, String tickerText){
showNotification(NOTIF_CONTSHARE_ID, drawableId, tickerText);
}
public void cancelContentShareNotif(){
if(!NgnMsrpSession.hasActiveSession(new NgnPredicate<NgnMsrpSession>() {
@Override
public boolean apply(NgnMsrpSession session) {
return session != null && NgnMediaType.isFileTransfer(session.getMediaType());
}}))
{
mNotifManager.cancel(NOTIF_CONTSHARE_ID);
}
}
public void refreshContentShareNotif(int drawableId){
if(!NgnMsrpSession.hasActiveSession(new NgnPredicate<NgnMsrpSession>() {
@Override
public boolean apply(NgnMsrpSession session) {
return session != null && NgnMediaType.isFileTransfer(session.getMediaType());
}}))
{
mNotifManager.cancel(NOTIF_CONTSHARE_ID);
}
else{
showNotification(NOTIF_CONTSHARE_ID, drawableId, "Content sharing");
}
}
public void showContentChatNotif(int drawableId, String tickerText){
showNotification(NOTIF_CHAT_ID, drawableId, tickerText);
}
public void cancelChatNotif(){
if(!NgnMsrpSession.hasActiveSession(new NgnPredicate<NgnMsrpSession>() {
@Override
public boolean apply(NgnMsrpSession session) {
return session != null && NgnMediaType.isChat(session.getMediaType());
}}))
{
mNotifManager.cancel(NOTIF_CHAT_ID);
}
}
public void refreshChatNotif(int drawableId){
if(!NgnMsrpSession.hasActiveSession(new NgnPredicate<NgnMsrpSession>() {
@Override
public boolean apply(NgnMsrpSession session) {
return session != null && NgnMediaType.isChat(session.getMediaType());
}}))
{
mNotifManager.cancel(NOTIF_CHAT_ID);
}
else{
showNotification(NOTIF_CHAT_ID, drawableId, "Chat");
}
}
public void showSMSNotif(int drawableId, String tickerText){
showNotification(NOTIF_SMS_ID, drawableId, tickerText);
}
public IScreenService getScreenService(){
if(mScreenService == null){
mScreenService = new ScreenService();
}
return mScreenService;
}
@Override
public Class<? extends NgnNativeService> getNativeServiceClass(){
return NativeService.class;
}
使用过程中分别获取配置服务和sip服务
mConfigurationService = Engine.getInstance().getConfigurationService();
mSipService = Engine.getInstance().getSipService();
下面贴一下其他作者的帖子说明。帖子地址http://blog.youkuaiyun.com/banketree/article/details/12580019
简介
imsdroid 是全功能的SIP / IMS的客户端,它基于doubango框架开发的app,doubango是目前世界上最好的3GPP IMS/RCS 嵌入式桌面系统框架,该框架提供了一套独特的功能,包括音频/视频通话、内容共享、消息、会议、通讯录等。
官网地址:http://code.google.com/p/imsdroid/
组件
1、Boghe
IMS/ RCS Windows客户端
2、IMSDroid
IMS/ RCS Android客户端(使用NGN堆栈)
3、iDoubs
IMS/ RCS iOS客户端(iPhone,iPad和iPod Touch)
4、OpenVCS
开源视频会议服务器,用于管理多点控制单元(MCU),每个MCU可以处理多达64人参与
5、Flash2IMS
使用Adobe Flash 的SIP/ IMS网关
支持功能
1、SIP ( RFC 3261 3GPP TS 24.229 REL- 9 )
2、 IPv4 IPv6 TCP UDP
3、信号编码 SigComp (RFC 3320 、3485、 4077 、4464 、4465、4896、5049、5112、1951)
4、通讯录
5、GSMA 通信
6、 语音(GSMA VoLTE)
7、GSMA RCS and GSMA VoLTE
8 、IMS 登陆 MD5加密
9、3GPP
10、服务路由探索
11、注册事件监听(注册事件、拨打事件、来电事件、消息事件。。。)
12、3GPP IP ( 3GPP TS 23.038 、24.040 、 24.011、 24.341、24.451短信)
13、语音呼叫( G729AB1 、 AMR - NB 、iLBC、 GSM 、 PCMA 、 PCMU、 Speex NB )
14、视频通话( H264、MP4V - ES 、Theora、 H.263 、 H.263 -1998 、H.261 )
15、双音多频DTMF ( RFC 4733 )
16、解决网络延迟和阻塞技术QoS negotiation using Preconditions (RFC 3312, 4032 and 5027)
17、SIP会话定时器( RFC 4028 )
18、临时响应( PRACK )
19、通信保持(3GPP TS 24.610 )
20、消息等待指示( 3GPP TS 24.606 )
21、E.164号码呼叫通过使用ENUM协议( RFC 3761 )
22、NAT穿越
23、一对一和群组聊天
项目如图
效果如图
项目分析
如何注册一个SIP / IMS服务器?如下:
获取配置服务:
获取SIP / IMS服务:
启动/停止引擎:
Contact Service
服务用于检索从本地地址簿
HTTP/HTTPS Service
HTTP / HTTPS服务用来发送和检索数据到/从远程服务器使用HTTP / HTTPS协议
Network Service
网络服务是用来管理WiFi和3G/4G网络连接
Sound Service
铃声,彩铃业务,警报
Storage Service
管理存储功能
Configuration Service
用来存储用户的设置,设置好后重新启动
History Service
用于存储/检索历史事件(音频/视频,通讯,……)
管理SIP/IMS栈
Audio/Video calls
音频/视频通话
得到有关的音频/视频呼叫状态如下:
拨打电话如下:
SMS and Chat
3GPP短信流
IM寻呼模式
监听事件
SIP/IMS服务负责对SIP协议相关的所有任务(登记,音频/视频电话,寻呼机模式IM…)等都有监听,所有的通知都是异步方式。
Realm
这个领域是身份验证的域名称,一个有效的SIP URI(sip:open-ims.test or sip:10.0.0.1),程序开始之前设置信息,如果Proxy-CSCF的地址丢失,那么堆栈将自动使用DNS SRV NAPTR 和DHCP机制动态发现。
希望原创作者不介意我这种结合方式,在此表示感谢。