1. 程式人生 > >Android VOIP撥打電話機制分析

Android VOIP撥打電話機制分析

建立.aidl檔案


ISipService.aidl內容如下:

[java] view plaincopyprint?
  1. /** 
  2.  * Copyright (C) 2010-2012 Regis Montoya (aka r3gis - www.r3gis.fr) 
  3.  * This file is part of CSipSimple. 
  4.  * 
  5.  *  CSipSimple is free software: you can redistribute it and/or modify 
  6.  *  it under the terms of the GNU General Public License as published by
     
  7.  *  the Free Software Foundation, either version 3 of the License, or 
  8.  *  (at your option) any later version. 
  9.  *  If you own a pjsip commercial license you can also redistribute it 
  10.  *  and/or modify it under the terms of the GNU Lesser General Public License 
  11.  *  as an android library. 
  12.  *
     
  13.  *  CSipSimple is distributed in the hope that it will be useful, 
  14.  *  but WITHOUT ANY WARRANTY; without even the implied warranty of 
  15.  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the 
  16.  *  GNU General Public License for more details. 
  17.  * 
  18.  *  You should have received a copy of the GNU General Public License
     
  19.  *  along with CSipSimple.  If not, see <http://www.gnu.org/licenses/>. 
  20.  *   
  21.  *  This file and this file only is also released under Apache license as an API file 
  22.  */
  23. package com.csipsimple.api;  
  24. import com.csipsimple.api.SipProfileState;  
  25. import com.csipsimple.api.SipCallSession;  
  26. import com.csipsimple.api.MediaState;  
  27. interface ISipService{  
  28.     /** 
  29.     * Get the current API version 
  30.     * @return version number. 1000 x major version + minor version 
  31.     * Each major version must be compatible with all versions of the same major version 
  32.     */
  33. .........  
  34. void makeCallWithOptions(in String callee, int accountId, in Bundle options);  
  35. }  
ISipService.aidl中定義了包含makeCallWithOptions
方法的介面ISipService。

自動編譯生成java檔案

eclipse中的ADT外掛會自動在aidl檔案中宣告的包名目錄下生成java檔案,如下圖所示:


ISipService.java
[java] view plaincopyprint?
  1. package com.csipsimple.api;  
  2. publicinterface ISipService extends android.os.IInterface  
  3. {  
  4. ……  
  5. //Place a call
  6. ublic void makeCallWithOptions(java.lang.String callee, int accountId, android.os.Bundle options) throws android.os.RemoteException;  
  7. }  
接下來就是實現ISipService.aidl中定義的介面,提供介面的例項供客戶端呼叫

IPC實現

專案中撥打電話  

void com.csipsimple.api.ISipService.makeCallWithOptions(String msg, String toNumber, long accountId)

結合程式碼一層層看呼叫

目錄:src\com\csipsimple\ui\dialpad

DialerFragment.java

[java] view plaincopyprint?
  1. private ISipService service;  
  2. private ServiceConnection connection = new ServiceConnection() {  
  3.     @Override
  4.     publicvoid onServiceConnected(ComponentName arg0, IBinder arg1) {  
  5.         service = ISipService.Stub.asInterface(arg1);  
  6.      ........  
  7.     }  
  8.     @Override
  9.     publicvoid onServiceDisconnected(ComponentName arg0) {  
  10.         service = null;  
  11.     }  
  12. };  
[java] view plaincopyprint?
  1. <span style="color:#333333;">   @Override
  2.     publicvoid placeCall() {  
  3.         placeCallWithOption(null);  
  4.     }  
  5. privatevoid placeCallWithOption(Bundle b) {  
  6.         if (service == null) {  
  7.             return;  
  8.         }  
  9.         String toCall = "";  
  10.         Long accountToUse = SipProfile.INVALID_ID;  
  11.         // Find account to use
  12.         SipProfile acc = accountChooserButton.getSelectedAccount();  
  13.         if (acc != null) {  
  14.             accountToUse = acc.id;  
  15.         }  
  16.         // Find number to dial
  17.         if(isDigit) {  
  18.             toCall = PhoneNumberUtils.stripSeparators(digits.getText().toString());  
  19.         }else {  
  20.             toCall = digits.getText().toString();  
  21.         }  
  22.         if (TextUtils.isEmpty(toCall)) {  
  23.             return;  
  24.         }  
  25.         // Well we have now the fields, clear theses fields
  26.         digits.getText().clear();  
  27.         // -- MAKE THE CALL --//
  28.         if (accountToUse >= 0) {  
  29.             // It is a SIP account, try to call service for that
  30.             try {  
  31.                </span><span style="color:#ff0000;"> service.makeCallWithOptions(toCall, accountToUse.intValue(), b);</span><span style="color:#333333;">  
  32.             } catch (RemoteException e) {  
  33.                 Log.e(THIS_FILE, "Service can't be called to make the call");  
  34.             }  
  35.         } elseif (accountToUse != SipProfile.INVALID_ID) {  
  36.             // It's an external account, find correct external account
  37.             CallHandlerPlugin ch = new CallHandlerPlugin(getActivity());  
  38.             ch.loadFrom(accountToUse, toCall, new OnLoadListener() {  
  39. 相關推薦

    Android VOIP撥打電話機制分析

    建立.aidl檔案 ISipService.aidl內容如下: [java] view plaincopyprint? /**   * Copyright (C) 2010-2012 Regis Montoya (aka r3gis 

    PigeonCall:一款Android VoIP網路電話App架構分析

    1.概述 PigeonCall,中文名“飛鴿電話”,是一款Android平臺的VoIP網路電話應用,但只工作於區域網,支援給任意區域網內使用該App的其他使用者撥打網路電話,可以在各大應用市場下載安裝,也可以直接點選這裡直接下載。 本應用是我利用了斷斷續續將近大半年的業餘時間開發出來的,目的是想研

    unity+android撥打電話

    package com.luoyikun.call; import android.app.Activity; import android.app.Fragment; import android.content.Context; import androi

    (O)Telephony分析之通話流程分析(二)撥打電話流程分析(上)

    撥打電話,是從通話的撥號盤開始的,而撥號盤的介面是在DialpadFragment,因此,需要從這個地方進行分析一.撥號盤介面撥號流程 public void onClick(View view) { ...... if (resId == R.id.dia

    深入理解Android Telephony 之RILD機制分析

    RILD負責modem和RILJ端的通訊,資訊分兩種:unsolicited和solicited,前者是由modem主動上報的,諸如時區更新、通話狀態、網路狀態等訊息,後者是RILJ端發請求並需要modem反饋的資訊。RILJ與RILD之間的通訊由主執行緒s_t

    android實現撥打電話但不彈出撥號介面

    這裡只提供一個大概的思路,整個流程不是我一個人就能完成的。測試機型為htc one x,Android版本4.2.2,已ROOT。 要實現撥號程式可能很簡單,一個簡單的Intent就能實現,從發出意圖到真正實現撥號的程式碼中間還執行了很多其他方法,這都是android底層原

    android呼叫撥打電話(包括執行時許可權)

    /** * 撥打電話(跳轉到撥號介面,使用者手動點選撥打) * * @param phoneNum 電話號碼 */ public void diallP

    android N 撥打電話流程(MO)

    本流程圖基於MTK平臺 Android 7.0,撥打的普通電話,本流程只作為溝通學習使用 整體流程圖 流程中部分重點知識 packages-apps目錄 dialer應用的DialpadFragment.onClick中,通過使用者

    【原創】源碼角度分析Android的消息機制系列(一)——Android消息機制概述

    run 權限 開發 等待 通過 讀取 概述 走了 color ι 版權聲明:本文為博主原創文章,未經博主允許不得轉載。 1.為什麽需要Android的消息機制 因為Android系統不允許在子線程中去訪問UI,即Android系統不允許在子線程中更新UI。 為什麽不允許

    【原創】源碼角度分析Android的消息機制系列(二)——ThreadLocal的工作過程

    機制 simple hand 這就是 數據存儲 read etc lena 並且 ι 版權聲明:本文為博主原創文章,未經博主允許不得轉載。 在上一篇文章中,我們已經提到了ThreadLocal,它並非線程,而是在線程中存儲數據用的。數據存儲以後,只能在指定的線程中獲取到數據

    【原創】源碼角度分析Android的消息機制系列(三)——ThreadLocal的工作原理

    沒有 cit gen 管理 pre 靜態 bsp 允許 clas ι 版權聲明:本文為博主原創文章,未經博主允許不得轉載。 先看Android源碼(API24)中對ThreadLocal的定義: public class ThreadLocal<T>

    【原創】源碼角度分析Android的消息機制系列(四)——MessageQueue的工作原理

    enc 容易 工作 trie oss 當前 within which ptime ι 版權聲明:本文為博主原創文章,未經博主允許不得轉載。 MessageQueue,主要包含2個操作:插入和讀取。讀取操作會伴隨著刪除操作,插入和讀取對應的方法分別為enqueueMes

    【原創】源碼角度分析Android的消息機制系列(六)——Handler的工作原理

    urn long empty isa pat stat 開啟 it is performed ι 版權聲明:本文為博主原創文章,未經博主允許不得轉載。 先看Handler的定義: /** * A Handler allows you to send and proc

    Android源碼的角度分析Binder機制

    androidIPC為了弄懂IPC的來龍去脈,我將從以下三個方面為大家來講解,希望對大家理解IPC會有幫助什麽是IPCIPC是Inter Process Communication的縮寫,其意思就是進程間的通信,也就是兩個進程之間的通信過程。我們都知道在Android系統中,每個應用都運行在一個進程上,具有自

    Android撥打電話號功能

    在本篇博文中將為大家提供兩種用程式碼實現調起電話簿,打電話功能,其實很簡單,只是新增一個許可權和一個方法的事 1、新增許可權 <uses-permission android:name="android.permission.CALL_PHONE" /> 2、調起撥號頁面,不

    Android撥打電話工具類

      歡迎關注技術公眾號,微訊號搜尋ColorfulCode 程式碼男人 分享技術文章,投稿分享,不限技術種類,不限技術深度,讓更多人因為分享而受益。 動態許可權框架使用的Acp,封裝撥打電話兩種常用模式,程式碼如下: public class CallPhoneU

    android 休眠喚醒機制分析(一) — wake_lock【轉】

    Android的休眠喚醒主要基於wake_lock機制,只要系統中存在任一有效的wake_lock,系統就不能進入深度休眠,但可以進行裝置的淺度休眠操作。wake_lock一般在關閉lcd、tp但系統仍然需要正常執行的情況下使用,比如聽歌、傳輸很大的檔案等。本文主要分析driver層wake_lock的實現。

    Android非同步訊息處理機制詳解及原始碼分析

    PS一句:最終還是選擇CSDN來整理髮表這幾年的知識點,該文章平行遷移到CSDN。因為CSDN也支援MarkDown語法了,牛逼啊! 【工匠若水 http://blog.csdn.net/yanbober 轉載煩請註明出處,尊重分享成果】 最近相對來說比較閒,加上養病,所

    Android IntentService原始碼理解 及 HandlerThread構建訊息迴圈機制分析

      前言:前面寫了Handler的原始碼理解,關於Handler在我們Android開發中是到處能見到的非同步通訊方式。那麼,在Android原生裡,有那些也有到了Handler機制的呢?有很多,比如我們今天所要理解分析的IntentService就使用到了Handler。接下來,我們來深入瞭解一下。   

    84.android 指定哪個SIM卡撥打電話

    //第一步 許可權: <uses-permission android:name="android.permission.CALL_PHONE" /> //Activity裡使用:  //撥號請求碼 public static final i